Skip to content

Instantly share code, notes, and snippets.

@cdock1029
Created March 18, 2017 22:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdock1029/9f3a58f352663ea90f8b9675412c4aea to your computer and use it in GitHub Desktop.
Save cdock1029/9f3a58f352663ea90f8b9675412c4aea to your computer and use it in GitHub Desktop.
firebase-functions express.js path fix
const app = require('express')();
// define your routes, etc ...
exports.route = functions.https.onRequest((req, res) => {
// https://some-firebase-app-id.cloudfunctions.net/route
// without trailing "/" will have req.path = null, req.url = null
// which won't match to your app.get('/', ...) route
if (!req.path) {
// prepending "/" keeps query params, path params intact
req.url = `/${req.url}`
}
return app(req, res)
});
@flasd
Copy link

flasd commented Jun 23, 2017

@cdock1029 How did you point the hosting to the function? I'm doing:

{
    "hosting": {
        "public": "public",
        "rewrites": [{
            "source": "**",
            "function": "helloWorld"
        }]
    }
}

It doesnt' work for the index path. It only works for /** paths.
Is this part of this issue?

@anantanandgupta
Copy link

it is not working for the "**" as @flasd mentioned earlier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment