Skip to content

Instantly share code, notes, and snippets.

@atbe
Last active July 1, 2017 19:47
Show Gist options
  • Save atbe/1f4e67ba024a3cf45192e1051644d84a to your computer and use it in GitHub Desktop.
Save atbe/1f4e67ba024a3cf45192e1051644d84a to your computer and use it in GitHub Desktop.
Firebase Functions /api/users Sub-Route
import * as express from "express";
// This is the router which will be imported in our
// api hub (the index.ts which will be sent to Firebase Functions).
export let userRouter = express.Router();
// Now that we have a router, we can define routes which this router
// will handle. Please look into the Express documentation for more info.
userRouter.get("/:uid", async function getUser(req: express.Request, res: express.Response) {
// ...
// just like before
const uid = req.params.uid;
res.status(200).send(`You requested user with UID = ${uid}`);
// ...
});
// Useful: Let's make sure we intercept un-matched routes and notify the client with a 404 status code
userRouter.get("*", async (req: express.Request, res: express.Response) => {
res.status(404).send("This route does not exist.");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment