refactor authentication middleware and clean up config comments
This commit is contained in:
parent
65d4779083
commit
a19070c767
9
index.js
9
index.js
@ -1,20 +1,25 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const fileUpload = require('express-fileupload');
|
const fileUpload = require('express-fileupload');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const mime = require( 'mime' );
|
const mime = require('mime');
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 3000;
|
const port = 3000;
|
||||||
|
|
||||||
const uploadPath = process.env.UPLOAD_PATH || '/tmp';
|
const uploadPath = process.env.UPLOAD_PATH || '/tmp';
|
||||||
const config = process.env.config || '{ "uploadGroups": [{ "matcher": "^test.*\.txt$", "groupSize": 3}] }';
|
// const config = process.env.CONFIG || "{ \"uploadGroups\": [] }";
|
||||||
|
//const config = process.env.CONFIG || "{ \"uploadGroups\": [{ \"matcher\": \"^mmkb-android-.*-test\\.apk$\", \"groupSize\": 3},{ \"matcher\": \"^mmkb-android-.*-int\\.apk$\", \"groupSize\": 3},{ \"matcher\": \"^mmkb-android-.*-prod\\.apk$\", \"groupSize\": 3}] }";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.use(fileUpload());
|
app.use(fileUpload());
|
||||||
|
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
|
if (process.env.API_KEY) {
|
||||||
const authenticated = req.get('Authorization') === 'Bearer ' + process.env.API_KEY;
|
const authenticated = req.get('Authorization') === 'Bearer ' + process.env.API_KEY;
|
||||||
if (!authenticated) {
|
if (!authenticated) {
|
||||||
return res.status(401).send('Unauthorized');
|
return res.status(401).send('Unauthorized');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user