diff --git a/src/server.js b/src/server.js index 4f8674c..9435877 100644 --- a/src/server.js +++ b/src/server.js @@ -186,6 +186,23 @@ fastify.get('/api/:shortcode/visits', async (req, res) => { return visits; }); +//Get url api route +fastify.delete('/api/:shortcode', async (req, res) => { + const shortcode = req.params.shortcode; + + //This should never happen but better safe than 500 + if (!shortcode) { + return 404; + } + + await knex('urls') + .where('shortcode', '=', shortcode) + .delete(); + + res.statusCode = 204; + return true; +}); + /** * Checks for some default providers with custom url schemes (amazon and youtube r/n) * @param {string} target The target URL