I am currently facing an issue with handling a custom 404 error using Firebase Hosting and Functions. The code I have provided below works perfectly fine on localhost, but once deployed, Firebase Hosting returns a 500 error instead of the expected 404.
-> returns "hello world"https://xxxx.web.app/myfunction/hello
-> returns a 500 errorhttps://xxxx.web.app/myfunction/404
http://localhost/myfunction/404
-> returns a custom 404 page
I am seeking help to identify what might be causing this unexpected behavior.
Below is the simplified code snippets for my index.js file:
const functions = require('firebase-functions');
exports.myfunction = functions.region('asia-east1').runWith({maxInstances: 2}).https.onRequest((request, response) => {
if (request.path == '/myfunction/hello') {
return response.send("hello world")
}
response.set('X-Cascade', 'PASS');
return response.status(404).end()
});
And here is the firebase.json configuration:
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
}
],
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/myfunction/*",
"function": "myfunction",
"region": "asia-east1"
}
]
}
}
Additional information about the file structure:
.
├── firebase.json
├── functions
│ ├── index.js
│ └── package.json
└── public
├── 404.html
└── index.html