add password protection

This commit is contained in:
Bilal Catic
2019-05-24 10:37:42 +02:00
parent c0788d7a43
commit dbc203fa44
3 changed files with 36 additions and 0 deletions

View File

@@ -1,14 +1,33 @@
'use strict';
const express = require("express");
const basicAuth = require('express-basic-auth');
const path = require('path');
const routes = require('./routes');
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')));