Oli*_*xon 5 firebase firebase-hosting
我的域似乎重定向到index.html和所有子链接就好了.
问题是它不会重定向到api规则"source": "/api/**"
我已经使用整个firebase网址(没有自定义域)手动检查API并且它可以工作.
如何让domain.com/somelink和domain.com/api/somelink联合工作?
这是配置.
firebase.json
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/api/**",
"function": "api"
},
{
"source": "**",
"destination": "/index.html"
}
]
},
"storage": {
"rules": "storage.rules"
}
}
Run Code Online (Sandbox Code Playgroud)
如此处所述/sf/ask/3147175671/#45224176
创建一个主应用程序来托管所有其他顶级功能。
const funtions = require('firebase-functions');
const express = require('express');
const app = express();
app.get('/users/:userId/:userData/json', (req, res) => {
// Do App stuff here
}
// A couple more app.get in the same format
// Create "main" function to host all other top-level functions
const main = express();
main.use('/api', app);
exports.main = functions.https.onRequest(main);
Run Code Online (Sandbox Code Playgroud)
firebase.json
{
"source": "/api/**", // "**" ensures we include paths such as "/api/users/:userId"
"function": "main"
}
Run Code Online (Sandbox Code Playgroud)
使用主钩。
const hooks = express();
main.use('/hooks/, hooks);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
294 次 |
| 最近记录: |