Created
July 1, 2017 18:18
-
-
Save atbe/647fb135de3e7d632c4e62695fe48df5 to your computer and use it in GitHub Desktop.
Firebase Functions - Attaching the /users Router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as express from "express"; | |
import * as admin from "firebase-admin"; | |
import * as functions from "firebase-functions"; | |
import * as usersApi from "./api/users"; | |
admin.initializeApp(functions.config().firebase); | |
const app = express(); | |
// https://expressjs.com/en/advanced/best-practice-security.html#at-a-minimum-disable-x-powered-by-header | |
app.disable("x-powered-by"); | |
// Any requests to /api/users will be routed to the user router! | |
app.use("/users", usersApi.userRouter); | |
// Again, lets be nice and help the poor wandering servers, any requests to /api | |
// that are not /api/users will result in 404. | |
app.get("*", async (req: express.Request, res: express.Response) => { | |
res.status(404).send("This route does not exist."); | |
}); | |
exports.api = functions.https.onRequest(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment