Make password configurable / add UI for upload

This commit is contained in:
Senad Uka
2019-05-28 13:48:58 +02:00
parent 84443783da
commit d850aef0b8
22 changed files with 353 additions and 45 deletions

View File

@@ -1,34 +1,26 @@
'use strict';
require('dotenv').config();
const express = require("express");
const basicAuth = require('express-basic-auth');
const path = require('path');
const routes = require('./routes');
const { myAuthorizer, getUnauthorizedResponse } = require('./helpers/auth');
const app = express();
const port = process.env.PORT || 5000;
function myAuthorizer(username, password) {
const userMatches = basicAuth.safeCompare(username, 'senadU');
const passwordMatches = basicAuth.safeCompare(password, 'Tulipan*123*');
return userMatches & passwordMatches
}
function getUnauthorizedResponse(req) {
return 'Forbidden';
}
app.use('/api', routes);
app.use(basicAuth({
authorizer: myAuthorizer,
challenge: true,
unauthorizedResponse: getUnauthorizedResponse
}));
//Static file declaration
app.use(express.static(path.join(__dirname, 'client/build')));
@@ -44,4 +36,5 @@ app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/client/public/index.html'));
});
app.listen(port, () => console.log(`App running on port ${port}!`));