From 90a2b06f23535a62e5df756562605920fc9e27df Mon Sep 17 00:00:00 2001 From: "Zander M." Date: Wed, 27 Sep 2023 02:22:23 -0400 Subject: [PATCH] Add API key validation route. --- app.js | 2 -- routes/api.js | 58 +++++++++++++++++++++++++++------------------------ 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/app.js b/app.js index 7206c3f..940f982 100644 --- a/app.js +++ b/app.js @@ -5,7 +5,6 @@ const cookieParser = require('cookie-parser') const logger = require('morgan') const indexRouter = require('./routes/index') -const usersRouter = require('./routes/users') const apiRouter = require('./routes/api') const app = express() @@ -21,7 +20,6 @@ app.use(cookieParser()) app.use(express.static(path.join(__dirname, 'public'))) app.use('/', indexRouter) -app.use('/users', usersRouter) app.use('/api', apiRouter) // catch 404 and forward to error handler diff --git a/routes/api.js b/routes/api.js index 68f7b8f..3375fe1 100644 --- a/routes/api.js +++ b/routes/api.js @@ -1,18 +1,18 @@ const express = require('express') const pckg = require('../package.json') -const branchName = require('current-git-branch'); +const branchName = require('current-git-branch')(); const router = express.Router() router.get('/', (req, res) => { res.json({ "api": pckg.prettyName, "version": pckg.version, - "stream": branchName() + "stream": branchName }) }) -router.get('/mod/:modname', (req, res) => { - // Found +router.get('/mod/:modname/:modversion?', (req, res) => { + // Found mod res.json({ "id": 0, "name": "example", @@ -26,14 +26,7 @@ router.get('/mod/:modname', (req, res) => { ] }) - // Not Found - // res.status(404).json({ - // "error": "Mod does not exist" - // }) -}) - -router.get('/mod/:modname/:modversion', (req, res) => { - // Found + // Found mod version res.json({ "id": 0, "md5": "51c1305b56249804926e38fcf3e46640", @@ -41,14 +34,14 @@ router.get('/mod/:modname/:modversion', (req, res) => { "url": "https://example.com/file.zip", }) - // Mod Not Found + // Version Not Found // res.status(404).json({ - // "error": "Mod does not exist" + // "error": "Mod version does not exist" // }) - // Version Not Found + // Mod Not Found // res.status(404).json({ - // "error": "Mod version does not exist" + // "error": "Mod does not exist" // }) }) @@ -62,7 +55,7 @@ router.get('/modpack', (req, res) => { }) }) -router.get('/modpack/:slug', (req, res) => { +router.get('/modpack/:slug/:build?', (req, res) => { // With Slug res.json({ "name": "examplepack", @@ -75,13 +68,6 @@ router.get('/modpack/:slug', (req, res) => { ] }) - // Modpack Not Found - // res.status(404).json({ - // "error": "Modpack does not exist" - // }) -}) - -router.get('/modpack/:slug/:build', (req, res) => { // Build found res.json({ "minecraft": "1.20.1", @@ -99,15 +85,33 @@ router.get('/modpack/:slug/:build', (req, res) => { ] }) + // Build Not Found + // res.status(404).json({ + // "error": "Build does not exist" + // }) // Modpack Not Found // res.status(404).json({ // "error": "Modpack does not exist" // }) +}) + +router.get('/verify/:key?', (req, res) => { + // Key validated + res.json({ + valid: "Key validated.", + name: "API KEY", + created_at: "A long time ago" + }) + + // Invalid key provided + // res.json({ + // error: 'Invalid key provided.' + // }) - // Build Not Found - // res.status(404).json({ - // "error": "Build does not exist" + // No key provided + // res.json({ + // error: 'No API key provided.' // }) })