Skip to content

Instantly share code, notes, and snippets.

@J3698
Created April 18, 2020 02:46
Show Gist options
  • Save J3698/31fdf73ef0f189382b5fae6fabf9944e to your computer and use it in GitHub Desktop.
Save J3698/31fdf73ef0f189382b5fae6fabf9944e to your computer and use it in GitHub Desktop.
// GET route for custom URLs
app.get('/custom', (req, res) => {
// sanitize input
if (typeof (req.query.longUrl) !== "string" ||
typeof (req.query.customUrl) !== "string") {
res.send({"shortened": null});
return;
}
let longUrl = qualify(req.query.longUrl);
let customUrl = req.query.customUrl;
if (customWordUnavailable(longUrl, customUrl)) {
res.send({"shortened": null});
} else {
customUrl = createCustomMapping(longUrl, customUrl);
res.send({"shortened": customUrl});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment