Skip to content

Commit

Permalink
Add API key validation route.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZandercraftGames committed Sep 27, 2023
1 parent 8f1241c commit 90a2b06
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
2 changes: 0 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
58 changes: 31 additions & 27 deletions routes/api.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const express = require('express')

Check failure on line 1 in routes/api.js

View workflow job for this annotation

GitHub Actions / Qodana for JS

Standard code style

Standard code style: Install the 'eslint' package
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",
Expand All @@ -26,29 +26,22 @@ 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",
"filesize": 0,
"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"
// })
})

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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.'
// })
})

Expand Down

0 comments on commit 90a2b06

Please sign in to comment.