I have set up hosting on Firebase and configured my Node.js express app following the documentation provided by Google. Including the proper folder structure and command line instructions to init firebase and firebase-functions.
Folder Structure:
Project
-- functions
-- node_modules
-- index.js
-- package.json
-- public
-- index.html
-- 404.html
.firebaserc
firebase.json
I have added the express app to the firebase functions http request via the code below:
// Set up endpoint
app.get('/api', (req, res) => {
res.json({
message: 'Welcome to the Line Prophet API. Good luck.'
})
});
/**
* Firebase cloud functions
*/
exports.app = functions.https.onRequest(app);
My Firebase.json file is set up to direct all request to the app destination:
{
"hosting": {
"public": "public",
"rewrites": [
{
"source": "**",
"destination": "app"
}
]
}
}
Once I run firebase deploy from my parent directory everything goes through fine and it says the app is deployed:
However after that I navigate to https://line-prophet.web.app/api and I recieve a 404 page not found error.
I have tried to run this locally with firebase serve and I have the same issue. This was working briefly which is why I feel as though everything is set up correctly, however after deploying again it has broken for good. Any tips are appreciated. Thanks!
The latest deployments say there are only 4 files deployed to Firebase which seems very low. I checked the Functions tab and I do see that "app" is in there and the source code is correct.
app.listen
in Cloud Functions. The infrastructure manages all the incoming sockets and delivers requests to your functions (when configured correctly). – Doug Stevenson"destination": "app"
with"function": "index"
, why useapp
? its not a file or route, see docs – Lawrence Cherone