diff options
| author | Carson Fleming <cflems@cflems.net> | 2023-10-20 23:37:28 -0400 |
|---|---|---|
| committer | Carson Fleming <cflems@cflems.net> | 2023-10-20 23:37:28 -0400 |
| commit | 5636edd5b6af3486284b430f660b1b9e309a3671 (patch) | |
| tree | f065d63d75ba3aa08eefa51c2cab407dcac859c6 /api-routes.js | |
| parent | 5b4f8c220bbcbe1ee4b684f91db7cc419e423a41 (diff) | |
| download | fle.ms-5636edd5b6af3486284b430f660b1b9e309a3671.tar.gz | |
Bring it all together and nitpick the appearance
Diffstat (limited to 'api-routes.js')
| -rw-r--r-- | api-routes.js | 32 |
1 files changed, 0 insertions, 32 deletions
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; |
