Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to handle root path request with node.js on firebase hosting?

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.

This is my firebase.json

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

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');
});

result

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

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

like image 967
yn1043 Avatar asked Oct 21 '25 04:10

yn1043


1 Answers

See 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

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

So https://myurl/ get static content /index.html.

Can you try remove public/index.html?


I tried. I can rewrite.

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

And you should check https://firebase.google.com/docs/hosting/functions .

like image 66
zkohi Avatar answered Oct 24 '25 10:10

zkohi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!