Skip to content

Instantly share code, notes, and snippets.

@nickpalenchar
Created April 9, 2018 20:39
Show Gist options
  • Save nickpalenchar/940f9671fe17a9b541c7bf9b595d9f71 to your computer and use it in GitHub Desktop.
Save nickpalenchar/940f9671fe17a9b541c7bf9b595d9f71 to your computer and use it in GitHub Desktop.
router.post('/new-link', requireAuthentication, (req, res) => {
let { expandedUrl, customName } = req.body;
  if(!/^https?:\/\//.test(expandedUrl)) expandedUrl = "http://" + expandedUrl; // add `http://` if not already provided, for consistency.
tryLink()
.then(result => { 
res.redirect('/dashboard?success=' + JSON.stringify(result));
})
.catch( err => {
if(err.nick) res.render('error', {err} );
else res.redirect('/error?code=1');
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment