Created
January 16, 2018 09:08
-
-
Save MarcL/2edc4d95d5280bacc62fd95ebe14a2ec to your computer and use it in GitHub Desktop.
Quick Node.js Express endpoint to redirect to a Messenger page
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 express = require('express'); | |
const app = express(); | |
// Call this from JSON API like this: | |
// | |
// https://myserver.com/1920147214903175/GetEBook | |
// | |
app.get('/:fbpage/:reference', (request, response) => { | |
// Get the page and reference | |
// NOTE: There is no error checking here so it assumes that the parameters are always passed | |
const {fbpage, reference} = request.params; | |
// Create the Facebook Messenger URL | |
const messengerUrl = `https://m.me/${fbpage}?ref=${reference}`; | |
// Redirect to the page | |
response.redirect(messengerUrl); | |
}); | |
app.listen(process.env.PORT || 8080, () => { | |
console.log('Your app is listening on port ' + listener.address().port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you Marc for doing all this just for me! <3 <3
I'll check it out once I have the server setup. I'm rushing because I need to confirm my deliverable by this week. I'm so grateful, for your help. Appreciate it!