js css html

firebase deploy functions & host

2020-01-03  本文已影响0人  Jason_风筝
1. firebase init functions 
2. firebase init hosting
3. cd functions -> npm i firebase-functions express --save

如果还没安装tools, 请:  npm install -g firebase-tools
它会创建functions 文件夹, code 写在fucntions 中, 结构如下图


{
    "hosting": {
        "public": "public",
        "rewrites": [
            {
                "source": "**",
                "function": "app"
            }
        ]
    }
}

其中,  "function": "app" , 为提供出来的function, ** 表示, 任何请求都会走它
const functions = require('firebase-functions');
const express = require('express');
const app = express()

app.get('/timestamp', function (req, res) {
    res.send(`${Date.now()}`);
})

app.get('/timestamp-cached', function (req, res) {
    /// 让响应缓存 
    res.set('Cache-Control','public, max-age=300, s-maxage=600');
    res.send(`${Date.now()}`);
})
exports.app = functions.https.onRequest(app);
firebase serve --only functions,hosting
firebase use --clear
firebase use xxx(你的firebase project id)
firebase deploy --only functions,hosting

Code

上一篇 下一篇

猜你喜欢

热点阅读