Created
November 27, 2020 21:09
-
-
Save leeprobert/495a3e3930d50d0aa62b1172ad9481a6 to your computer and use it in GitHub Desktop.
Simple Firebase function for redirecting to a URL by checking a query string
This file contains hidden or 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
const functions = require('firebase-functions'); | |
const admin = require('firebase-admin'); | |
const defaultApp = admin.initializeApp(functions.config().firebase); | |
exports.redirect = functions.https.onRequest((req, res) => { | |
const redirectId = req.query.id; | |
console.log(redirectId); | |
var redirectUrl; | |
switch(redirectId){ | |
default : | |
redirectUrl = "https://www.youtube.com/watch?v=hms44V0cGhQ"; | |
console.log(redirectUrl); | |
break; | |
} | |
res.redirect(redirectUrl); | |
}); | |
// https://us-central1-*****.cloudfunctions.net/redirect?id=foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment