I'm using sample code to serve dynamic content on firebase
I was able to deploy hosting & function both as suggested in sample code
but, when I access function url from firebaseapp url it fails, whereas when I access it directly from cloudfunctions url it works
```
"hosting": {
"public": "dist",
"ignore": [
"firebase.json",
"/.",
"/node_modules/"
],
"rewrites": [
{
"source": "/api/",
"function": "api"
},
{
"source": "*",
"destination": "index.html"
}
]
},
"database": {
"rules": "database.rules.json"
}
}
**Failing Function code used (including require/import commands at the top)**
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors({origin: true}));
app.get('login', (req, res) => {
return res
.type('application/manifest+json')
.status(200)
.send(JSON.stringify({
message: 'OK',
}, null, 2));
});
exports.api = functions.https.onRequest(app);
```
Steps to set up and reproduce
GET xxxx.firebaseapp.com/api/login => Can not GET api/login | Status 404
GET us-central1-xxxx.cloudfunctions.net/api/login => OK | Status 200
Errors in the console log shows that hosting url is proerly forwarded to function but then function return 404
Screenshots

GET xxxx.firebaseapp.com/api/login => OK | Status 200
GET xxxx.firebaseapp.com/api/login => Can not GET api/login | Status 404
I think you need to add a slash to the path in your functions code:
Instead of app.get('login',.., try app.get('/login',.., like in this example:
Hey @jhuleatt deployed after changing it to '/login' still facing problem.
I even deployed the same sample app, that too didn't work.
Hey @sumitkanoje, I was having the same problem and after some testing, it looks like express endpoints have to include '/api' in the urls, which in the examples, they don't. So change your '/login' to include '/api/login'
Hey @rolandszpond It worked, thanks for the help :)
hey @sumitkanoje @rolandszpond I'm facing a similar issue, direct http request to the function works great, but when accessing through hosting using the rewrites rule I'm getting a 404, any guess ?
For me it was an issue due to my node.js version. I was using node 12. The npm start always told me, that this was incompatible, Maybe try again w/ node 10 or 8
I also ran into this issue but I forgot to RTFM:
Firebase Hosting supports Cloud Functions in us-central1 only
my function isn't running in us-central1, so it won't work :(
@lukasvan3l Damn, I think I am in the same situation.. Does it mean I won't be able to run a Next JS solution using the Firebase Hosting/Functions in europe-west1 region? :(
Most helpful comment
Hey @sumitkanoje, I was having the same problem and after some testing, it looks like express endpoints have to include '/api' in the urls, which in the examples, they don't. So change your '/login' to include '/api/login'