Initial setup
This commit is contained in:
47
server.js
Normal file
47
server.js
Normal file
@@ -0,0 +1,47 @@
|
||||
'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')));
|
||||
|
||||
//production mode
|
||||
if(process.env.NODE_ENV === 'production') {
|
||||
app.get('*', (req, res) => {
|
||||
res.sendfile(path.join(__dirname = 'client/build/index.html'));
|
||||
});
|
||||
}
|
||||
|
||||
//build mode
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(__dirname + '/client/public/index.html'));
|
||||
});
|
||||
|
||||
app.listen(port, () => console.log(`App running on port ${port}!`));
|
||||
Reference in New Issue
Block a user