From 5636edd5b6af3486284b430f660b1b9e309a3671 Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Fri, 20 Oct 2023 23:37:28 -0400 Subject: Bring it all together and nitpick the appearance --- api-routes.js | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 api-routes.js (limited to 'api-routes.js') diff --git a/api-routes.js b/api-routes.js deleted file mode 100644 index 5c0ed7c..0000000 --- a/api-routes.js +++ /dev/null @@ -1,32 +0,0 @@ -const express = require('express'); -const Url = require('./db/url-schema.js'); -const utils = require('./utils.js'); -const router = express.Router(); - -router.all('/', async (req, res) => { - utils.sendBadRequestError(res, 'Nothing to be done at API root.'); -}); - -router.put('/:slug', async (req, res) => { - try { - const {url} = req.body; - const slug = req.params.slug.toLowerCase(); - if (!utils.isUrlFormatted(url)) - return utils.sendBadRequestError(res, 'URL "'+url+'" is malformatted. Must be a valid URL.'); - if (!utils.isAlphaNumeric(slug)) - return utils.sendBadRequestError(res, 'Slug "'+slug+'" is malformatted. Must be alphanumeric.'); - if (await Url.exists({slug: slug})) - return utils.sendBadRequestError(res, 'Slug "'+slug+'" already exists. Updates are not supported at this time.'); - - await new Url({url, slug}).save(); - utils.sendSuccessfulSlugCreation(res, slug); - } catch (err) { - utils.sendInternalServerError(res); - } -}); - -router.all('/*', async (req, res) => { - utils.sendNotFoundError(res); -}); - -module.exports = router; -- cgit v1.2.3