i cant fucking local test this thing

This commit is contained in:
Evert Prants 2020-01-06 22:23:18 +02:00
parent 20593c5ecc
commit 8ec4dc09ba
Signed by: evert
GPG Key ID: 1688DA83D222D0B5

View File

@ -167,7 +167,7 @@ async function init () {
// Simple URL validator
try {
let a = new URL(url)
if (a.protocol.indexOf('http') !== 0 || a.protocol.indexOf('ftp') !== -1) {
if (a.protocol.indexOf('http') !== 0 && a.protocol.indexOf('ftp') !== -1) {
throw new Error('Unsupported protocol')
}
} catch (e) {
@ -200,6 +200,10 @@ async function init () {
res.send(resp)
})
router.get('/shorten', (req, res) => {
res.send('<h1>Basic URL Shortener</h1><form action=""><input type="url" name="url" placeholder="URL to shorten"/><input type="submit" value="Go!"/></form>')
})
router.get('/shorten/:hash', async (req, res) => {
let hash = req.params.hash
let db = await dbPromise
@ -208,10 +212,6 @@ async function init () {
res.redirect(get.url)
})
router.get('/shorten', (req, res) => {
res.send('<h1>Basic URL Shortener</h1><form action=""><input type="url" name="url" placeholder="URL to shorten"/><input type="submit" value="Go!"></form>')
})
return router
}