It is a silly idea leaving a 404 to mean successful

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-04-07 14:39:45 +01:00
parent 9c45ecfdf1
commit a213014a0b
2 changed files with 17 additions and 15 deletions

28
app.js
View File

@ -17,15 +17,15 @@ const rateLimit = require('express-rate-limit')
const authenticate= require('./src/middlewares/auth.middlewares')
// Internal Requires
const log = require('./src/utils/log.utils'); // Log Helper
const version = require('./src/configs/version.configs'); // Version Strings
const listRtr = require('./src/routes/list.routes'); // /list endpoints
const ldbRtr = require('./src/routes/ldb.routes'); // /ldb endpoints
const kubeRtr = require('./src/routes/kube.routes'); // /kube endpoints
const findRtr = require('./src/routes/find.routes'); // /find endpoints
const issueRtr = require('./src/routes/issue.routes') // /issue endpoints
const statRtr = require('./src/routes/stats.routes'); // /stat endpoints
const regRtr = require('./src/routes/registration.routes'); // /auth endpoints
const log = require('./src/utils/log.utils'); // Log Helper
const version = require('./src/configs/version.configs'); // Version Strings
const listRtr = require('./src/routes/list.routes'); // /list endpoints
const ldbRtr = require('./src/routes/ldb.routes'); // /ldb endpoints
const kubeRtr = require('./src/routes/kube.routes'); // /kube endpoints
const findRtr = require('./src/routes/find.routes'); // /find endpoints
const issueRtr = require('./src/routes/issue.routes'); // /issue endpoints
const statRtr = require('./src/routes/stats.routes'); // /stat endpoints
const regRtr = require('./src/routes/registration.routes'); // /registration endpoints
// Set Server Configurations
const srvListen = process.env.OWL_SRV_LISTEN || "0.0.0.0"
@ -70,17 +70,17 @@ app.use('/api/v1/ldb', ldbRtr);
app.use('/api/v1/kube', kubeRtr);
app.use('/api/v1/find', findRtr);
app.use('/api/v1/issue', issueRtr);
app.use('/api/v1/stats', statRtr)
app.use('/api/v1/register', regRtr)
app.use('/api/v1/stats', statRtr);
app.use('/api/v1/register', regRtr);
// Authented Routes
app.use('/api/v1/ldbs', authenticate)
app.use('/api/v1/auth/test', authenticate) // Returns 401 if auth failed, 404 if successful.
app.use('/api/v1/auth/test', authenticate, (req, res) => res.status(200)) // Returns 401 if auth failed, 200 if successful.
// Number of proxies:
app.set('trust proxy', 3)
app.set('trust proxy', 4)
mode === "development"
? app.get('/api/v1/ip', (request, response) => response.send(request.ip))
? app.get('/api/v1/ip', (req, res) => res.send(req.ip))
: null
// Start Express

View File

@ -6,7 +6,7 @@ module.exports = async function authCheck(req, res, next) {
try {
var uuid = req.headers.uuid
} catch(err) {
log.out(`authMiddlewares: No authentication attempted`, "INFO")
log.out(`authMiddlewares: No authentication attempted`, "info")
err.status = 401
return next(err)
}
@ -15,8 +15,10 @@ module.exports = async function authCheck(req, res, next) {
if (!result) {
const err = new Error("Unauthorised");
err.status = 401
log.out(`authMiddlewares: Authentication attempted with incorrect key`, "warn")
return next(err)
} else {
log.out(`authMiddlewares: User authenticated`, "info")
return next()
}
} catch(err) {