Skip to content

Instantly share code, notes, and snippets.

@leeprobert
Created November 27, 2020 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leeprobert/495a3e3930d50d0aa62b1172ad9481a6 to your computer and use it in GitHub Desktop.
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
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