Files
old-psihologija/server.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-05-23 16:41:50 +02:00
'use strict';
const express = require("express");
2019-05-24 10:37:42 +02:00
const basicAuth = require('express-basic-auth');
2019-05-23 19:33:37 +02:00
const path = require('path');
2019-05-24 10:14:41 +02:00
const routes = require('./routes');
2019-05-23 16:41:50 +02:00
const app = express();
const port = process.env.PORT || 5000;
2019-05-24 10:37:42 +02:00
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';
}
2019-05-23 19:33:37 +02:00
2019-05-24 10:14:41 +02:00
app.use('/api', routes);
2019-05-24 10:37:42 +02:00
app.use(basicAuth({
authorizer: myAuthorizer,
challenge: true,
unauthorizedResponse: getUnauthorizedResponse
}));
2019-05-24 10:14:41 +02:00
2019-05-23 19:33:37 +02:00
//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) => {
2019-05-24 10:14:41 +02:00
res.sendFile(path.join(__dirname + '/client/public/index.html'));
2019-05-23 19:33:37 +02:00
});
2019-05-23 16:41:50 +02:00
app.listen(port, () => console.log(`App running on port ${port}!`));