Last active
July 1, 2017 19:47
-
-
Save atbe/1f4e67ba024a3cf45192e1051644d84a to your computer and use it in GitHub Desktop.
Firebase Functions /api/users Sub-Route
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"; | |
// 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