pis #12
28
app.js
28
app.js
@ -17,15 +17,15 @@ const rateLimit = require('express-rate-limit')
|
|||||||
const authenticate= require('./src/middlewares/auth.middlewares')
|
const authenticate= require('./src/middlewares/auth.middlewares')
|
||||||
|
|
||||||
// Internal Requires
|
// Internal Requires
|
||||||
const log = require('./src/utils/log.utils'); // Log Helper
|
const log = require('./src/utils/log.utils'); // Log Helper
|
||||||
const version = require('./src/configs/version.configs'); // Version Strings
|
const version = require('./src/configs/version.configs'); // Version Strings
|
||||||
const listRtr = require('./src/routes/list.routes'); // /list endpoints
|
const listRtr = require('./src/routes/list.routes'); // /list endpoints
|
||||||
const ldbRtr = require('./src/routes/ldb.routes'); // /ldb endpoints
|
const ldbRtr = require('./src/routes/ldb.routes'); // /ldb endpoints
|
||||||
const kubeRtr = require('./src/routes/kube.routes'); // /kube endpoints
|
const kubeRtr = require('./src/routes/kube.routes'); // /kube endpoints
|
||||||
const findRtr = require('./src/routes/find.routes'); // /find endpoints
|
const findRtr = require('./src/routes/find.routes'); // /find endpoints
|
||||||
const issueRtr = require('./src/routes/issue.routes') // /issue endpoints
|
const issueRtr = require('./src/routes/issue.routes'); // /issue endpoints
|
||||||
const statRtr = require('./src/routes/stats.routes'); // /stat endpoints
|
const statRtr = require('./src/routes/stats.routes'); // /stat endpoints
|
||||||
const regRtr = require('./src/routes/registration.routes'); // /auth endpoints
|
const regRtr = require('./src/routes/registration.routes'); // /registration endpoints
|
||||||
|
|
||||||
// Set Server Configurations
|
// Set Server Configurations
|
||||||
const srvListen = process.env.OWL_SRV_LISTEN || "0.0.0.0"
|
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/kube', kubeRtr);
|
||||||
app.use('/api/v1/find', findRtr);
|
app.use('/api/v1/find', findRtr);
|
||||||
app.use('/api/v1/issue', issueRtr);
|
app.use('/api/v1/issue', issueRtr);
|
||||||
app.use('/api/v1/stats', statRtr)
|
app.use('/api/v1/stats', statRtr);
|
||||||
app.use('/api/v1/register', regRtr)
|
app.use('/api/v1/register', regRtr);
|
||||||
|
|
||||||
// Authented Routes
|
// Authented Routes
|
||||||
app.use('/api/v1/ldbs', authenticate)
|
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:
|
// Number of proxies:
|
||||||
app.set('trust proxy', 3)
|
app.set('trust proxy', 4)
|
||||||
mode === "development"
|
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
|
: null
|
||||||
|
|
||||||
// Start Express
|
// Start Express
|
||||||
|
@ -6,7 +6,7 @@ module.exports = async function authCheck(req, res, next) {
|
|||||||
try {
|
try {
|
||||||
var uuid = req.headers.uuid
|
var uuid = req.headers.uuid
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
log.out(`authMiddlewares: No authentication attempted`, "INFO")
|
log.out(`authMiddlewares: No authentication attempted`, "info")
|
||||||
err.status = 401
|
err.status = 401
|
||||||
return next(err)
|
return next(err)
|
||||||
}
|
}
|
||||||
@ -15,8 +15,10 @@ module.exports = async function authCheck(req, res, next) {
|
|||||||
if (!result) {
|
if (!result) {
|
||||||
const err = new Error("Unauthorised");
|
const err = new Error("Unauthorised");
|
||||||
err.status = 401
|
err.status = 401
|
||||||
|
log.out(`authMiddlewares: Authentication attempted with incorrect key`, "warn")
|
||||||
return next(err)
|
return next(err)
|
||||||
} else {
|
} else {
|
||||||
|
log.out(`authMiddlewares: User authenticated`, "info")
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
|
Loading…
Reference in New Issue
Block a user