summaryrefslogtreecommitdiff
path: root/api-routes.js
diff options
context:
space:
mode:
Diffstat (limited to 'api-routes.js')
-rw-r--r--api-routes.js32
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;