Hi when I deploy my firebase web app, I get a 404 not found error when hitting endpoints.
Here is part of my index.js file found in my src/routes/functions folder.
const port = process.env.PORT || 80;
server.listen(port,'127.0.0.1');
console.debug('Server listening on port ' + port);
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "*",
authDomain: "*",
databaseURL: "*",
projectId: "*",
storageBucket: "*",
messagingSenderId: "93371481008",
appId: "*",
measurementId: "G-NR8N5HP6RZ"
};
// Initialize Firebase
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}else {
firebase.app(); // if already initialized, use that one
}
router.get('/test', function(req,res){
console.log("router map test");
res.send("test page");
});
When I deploy the firebase web app by typeing:
sudo firebase deploy
When I try and hit the test endpoint in index.js - curl -X GET https://PROJECT_ID/test
I get a 404 error.
Here is my firebase.json file:
"hosting": {
"public": "src/main/www",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
},```
"functions": [
{
"source": "src/routes/functions",
"codebase": "map-print",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
}
],
"rewrites": [
{
"source": "/test",
"function": "test"
}
]
}
You're missing to export the function itself.
I suppose you're using express
to handle your routes, so here's a minimal example:
import express from 'express'
const app = express()
app.get('/test', req, res => {
return res.send('hello world')
})
// this is what you're missing
exports.myFuncionName = functions.https.onRequest( app )