Skip to content

Instantly share code, notes, and snippets.

@jthegedus
Last active March 4, 2019 06:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jthegedus/b02f783febbf57cd1e66f817f331663c to your computer and use it in GitHub Desktop.
Save jthegedus/b02f783febbf57cd1e66f817f331663c to your computer and use it in GitHub Desktop.
Cloud Functions for Firebase - Express example 3/3 - using CORS and automatically appending a trailing slash
const functions = require("firebase-functions")
const cors = require("cors")
const express = require("express")
/* Express with CORS & automatic trailing '/' solution */
const app3 = express()
app3.use(cors({ origin: true }))
app3.get("*", (request, response) => {
response.send(
"Hello from Express on Firebase with CORS! No trailing '/' required!"
)
})
// not as clean, but a better endpoint to consume
const api3 = functions.https.onRequest((request, response) => {
if (!request.path) {
request.url = `/${request.url}` // prepend '/' to keep query params if any
}
return app3(request, response)
})
module.exports = {
api3
}
@PanwarParamveer
Copy link

nice

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