Skip to content

Commit cc11c71

Browse files
Merge pull request firebase#108 from firebase/nicolasgarnier-patch-1
Switching to using an Express Router
2 parents acaec08 + 990e2f9 commit cc11c71

File tree

1 file changed

+6
-5
lines changed
  • authorized-https-endpoint/functions

1 file changed

+6
-5
lines changed

authorized-https-endpoint/functions/index.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const admin = require('firebase-admin');
2020
admin.initializeApp(functions.config().firebase);
2121
const express = require('express');
2222
const cors = require('cors')({origin: true});
23-
const app = express();
23+
const router = new express.Router();
2424

2525
// Express middleware that validates Firebase ID Tokens passed in the Authorization HTTP header.
2626
// The Firebase ID token needs to be passed as a Bearer token in the Authorization HTTP header like this:
@@ -47,13 +47,14 @@ const validateFirebaseIdToken = (req, res, next) => {
4747
});
4848
};
4949

50-
app.use(cors);
51-
app.use(validateFirebaseIdToken);
52-
app.get('*', (req, res) => {
50+
router.use(cors);
51+
router.use(validateFirebaseIdToken);
52+
router.get('*', (req, res) => {
5353
res.send(`Hello ${req.user.name}`);
5454
});
5555

5656
// This HTTPS endpoint can only be accessed by your Firebase Users.
5757
// Requests need to be authorized by providing an `Authorization` HTTP header
5858
// with value `Bearer <Firebase ID Token>`.
59-
exports.authorizedHello = functions.https.onRequest(app);
59+
// NOTE: You need to add a trailing slash to the Function's URL becasue of this issue: https://github.com/firebase/firebase-functions/issues/27
60+
exports.authorizedHello = functions.https.onRequest(router);

0 commit comments

Comments
 (0)