gpt4 book ai didi

firebase - 如何在 firebase 托管上使用 node.js 处理根路径请求?

转载 作者:行者123 更新时间:2023-12-05 05:10:46 25 4
gpt4 key购买 nike

我正在使用 firebase 托管 + 函数开发网络系统。尽管在 firebase.json 上指定了重写规则,部分路由不起作用。

root/
 ├ functions/
 │ ├index.js
 │ ├routes/
 │ │ └ index.js
 │ └views/
 │ ├ index.jade
 │ └ sub.jade
 └ public/
└index.html // this is created by default. I don't want to use this.

这是我的 firebase.json

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

这是 node.js 代码。

router.get('/', function(req, res, next) {
res.render('index');
});

router.get('/subdir', function(req, res, next) {
res.render('sub');
});

结果

https://myurl/ -> public/index.html is shown.(not handled on node.js)
https://myurl/ -> handled on node.js

您知道如何在 firebase 托管上使用 node.js 处理根路径请求吗?

最佳答案

参见 https://firebase.google.com/docs/hosting/full-config#hosting_priority_order .

Priority order of Hosting responses

The different Firebase Hosting configuration options described on this page can sometimes overlap. If there is a conflict, Hosting determines its response using the following priority order:

  1. Reserved namespaces that begin with a /__/* path segment
  2. Configured redirects
  3. Exact-match static content
  4. Configured rewrites
  5. Custom 404 page
  6. Default 404 page

精确匹配静态内容的优先级高于配置重写。

所以https://myurl/获取静态内容/index.html

你能试试移除 public/index.html 吗?


我试过了。我可以重写。

参见 https://github.com/zkohi/firebase-hosting-using-functions-samples .

你应该检查https://firebase.google.com/docs/hosting/functions .

关于firebase - 如何在 firebase 托管上使用 node.js 处理根路径请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56272803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com