Files
old-psihologija/server.js

43 lines
972 B
JavaScript
Raw Normal View History

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