Skip to content

Instantly share code, notes, and snippets.

@atbe
Last active July 1, 2017 19:47
Show Gist options
  • Save atbe/a236b516953a922fc5d6ba16875d6a68 to your computer and use it in GitHub Desktop.
Save atbe/a236b516953a922fc5d6ba16875d6a68 to your computer and use it in GitHub Desktop.
Firebase Functions Complex getUser Route
import * as express from "express";
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
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");
app.get("/users/:uid", async function getUser(req: express.Request, res: express.Response) {
// Guess what, uid will NEVER be null in this context because of the Express router.
const uid = req.params.uid;
res.status(200).send(`You requested user with UID = ${uid}`);
});
// This line is important. What we are doing here is exporting ONE function with the name
// `api` which will always route
exports.api = functions.https.onRequest(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment