我似乎无法配置路由来连接firebase主机到我的云函数express应用程序。我试图设置为shown here,但行为似乎不同。我似乎不知道我做错了什么。请发送帮助,我快疯了。
索引.js
const functions = require("firebase-functions");
const app = require('./app');
exports.api = functions.https.onRequest(app);
应用程序.js
const app = express();
// ...
app.use(cors());
app.use('/params', paramsRoutes);
module.exports = app;
防火墙.json
{
"hosting": {
// ...
"rewrites": [
{
"source": "/api/**",
"function": "api"
},
// ...
]
}
}
1条答案
按热度按时间kqlmhetl1#
There is appropriate documentation that lists your requirement of hosting the Cloud Functions in Firebase Hosting using a custom domain.
firebase init functions
Also as per documentationwe can use rewrites to serve requests for a specific firebase hosting URL to a function. To do that you need to use "/api". You don't have to add the entire URL because you are redirecting from firebase hosting. So, when you add "/api" you are indicating to redirect requests going to "PROJECT_ID.web.app/api and PROJECT_ID.firebaseapp.com/api" to the function you specified.
If you want redirect every single URL to your host to an express app in Cloud Functions, you will need to do the following:
You can read more in the docs or follow this medium post for more details.
Check these links for similar implementation: