本文介绍了如何在Firebase托管上使用node.js处理根路径请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase托管+功能开发Web系统.尽管在firebase.json上指定了重写规则,路由的一部分不起作用.

I'm developing web system using firebase hosting + functions.Inspite of specifying rewrite rules on firebase.json,a part of routing doesn't work.

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

This is my firebase.json

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

这是node.js代码.

And this is node.js code.

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处理根路径请求.

Do you know how to handle root path request with node.js on firebase hosting.

推荐答案

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

此页面上描述的不同Firebase Hosting配置选项有时可能会重叠.如果存在冲突,托管将使用以下优先级顺序确定其响应:

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. 以/__/*路径段开头的保留名称空间
  2. 已配置的重定向
  3. 完全匹配静态内容
  4. 已配置的重写
  5. 自定义404页面
  6. 默认404页面
  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

完全匹配静态内容的优先级高于配置的重写.

Exact-match static content is high priority order than Configured rewrites.

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

您可以尝试删除public/index.html吗?

Can you try remove public/index.html?

我尝试过.我可以重写.

I tried. I can rewrite.

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

并且您应该检查 https://firebase.google.com/docs/hosting/functions .

这篇关于如何在Firebase托管上使用node.js处理根路径请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 18:11