Recently, I slightly updated my express code and tried to run it locally using firebase serve but it didn't work as expected. It always returned 404 status every route. then I decide to deploy it to test if it works, and it totally worked without any issue.
Here is my code
```const functions = require('firebase-functions');
const express = require('express');
const path = require('path');
const cors = require('cors');
const bodyParser = require('./node_modules/body-parser');
const app = express();
const homeRoute = require('./routes/home');
const productRoute = require('./routes/products');
const articleRoute = require('./routes/articles');
const aboutRoute = require('./routes/about');
const errController = require('./controllers/error');
app.set('view engine', 'ejs');
app.set('views', './views');
app.use(cors({origin: true}));
app.use(bodyParser.urlencoded({extended: false}));
app.use(express.static(path.join(__dirname, 'public')));
app.use(aboutRoute);
app.use(articleRoute);
app.use(productRoute);
app.use(homeRoute);
app.use(errController.get404Page);
exports.app = functions.https.onRequest(app);
```
Actually, I just run it locally a few days ago and it worked just fine but the issue just happened today. Is there any solution to fix this problem? I have to deploy my code every single time to test its functionality.
I get the same error. I have tried with the simple setup found here: https://firebase.google.com/docs/functions/http-events
It just returns 404.
const express = require('express');
const cors = require('cors');
const app = express();
// Automatically allow cross-origin requests
app.use(cors({ origin: true }));
// Add middleware to authenticate requests
app.use(myMiddleware);
// build multiple CRUD interfaces:
app.get('/:id', (req, res) => res.send(Widgets.getById(req.params.id)));
app.post('/', (req, res) => res.send(Widgets.create()));
app.put('/:id', (req, res) => res.send(Widgets.update(req.params.id, req.body)));
app.delete('/:id', (req, res) => res.send(Widgets.delete(req.params.id)));
app.get('/', (req, res) => res.send(Widgets.list()));
// Expose Express API as a single Cloud Function:
exports.widgets = functions.https.onRequest(app);
I use the version 6.9.2 of the firebase cli tool.
There is a bug on version 6.9.2 , you can downgrade your version (https://github.com/firebase/firebase-tools/issues/1293)
Or check this link below for another simple solution without downgrade;
There is a bug on version 6.9.2 , you can downgrade your version (#1293)
Or check this link below for another simple solution without downgrade;
I think so, my code worked just fine before I upgrade Firebase CLI. Thank for your help, it finally works
I have the same issue as @ArtyDev57 . I downgraded to 6.8.0 but now I'm getting a different error. Here is the debug:
[debug] [2019-05-15T16:15:22.882Z] Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator/logs'
at Object.mkdirSync (fs.js:773:3)
at Object.assertLogsPath (/usr/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator/src/emulator/logs.js:65:10)
at new Controller (/usr/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator/src/cli/controller.js:77:32)
at FunctionsEmulator.start (/usr/lib/node_modules/firebase-tools/lib/functionsEmulator.js:102:23)
at Object.start (/usr/lib/node_modules/firebase-tools/lib/serve/functions.js:7:33)
at /usr/lib/node_modules/firebase-tools/lib/serve/index.js:15:23
at arrayMap (/usr/lib/node_modules/firebase-tools/node_modules/lodash/lodash.js:639:23)
at Function.map (/usr/lib/node_modules/firebase-tools/node_modules/lodash/lodash.js:9556:14)
at _serve (/usr/lib/node_modules/firebase-tools/lib/serve/index.js:13:26)
at Command.module.exports.Command.description.option.option.option.option.before.action [as _action] (/usr/lib/node_modules/firebase-tools/lib/commands/serve.js:55:12)
[error]
[error] Error: An unexpected error has occurred.
Any idea how to fix this one?
@SebastianCApostolescu I believe this was a known issue in the legacy emulation environment, but I don't know a workaround, sorry.
In regards to the original question, when 6.9.3 comes out it'll have a fix specifically to help run express apps via https functions, so this issue has already been discussed / resolved in another thread :) If you're still seeing this after 6.9.3 comes out (within 48 hours or so) please re-open!
Sorry, I forgot to update @abeisgoat .
I managed to fix it. Turns out I lost ownership of @google-cloud/functions-emulator/logs or something like that. I managed to fix it by changing ownership or something like that. Sorry, I can't really be helpful since I am new to Linux I got to a point where I just simply copy/pasted everything I found on the internet.
Anyway... Thanks for the help and I hope it will get fixed soon!
i am still getting this 404 on the 6.10.0 but only for the DELETE method. I am using hosting rewrite to access the function. every other method (tested POST, GET only as of now) works. Can anyone please tell me if thats fixed.
@anantanandgupta would you mind opening a new issue for the DELETE bug?
@anantanandgupta would you mind opening a new issue for the
DELETEbug?
here you go #1325
Most helpful comment
@SebastianCApostolescu I believe this was a known issue in the legacy emulation environment, but I don't know a workaround, sorry.
In regards to the original question, when
6.9.3comes out it'll have a fix specifically to help run express apps viahttpsfunctions, so this issue has already been discussed / resolved in another thread :) If you're still seeing this after6.9.3comes out (within 48 hours or so) please re-open!