jobscraper/server/server.js

62 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-05-19 09:05:04 +00:00
/**
* Created by WebStorm.
* User: martin
* Date: 14/05/2020
* Time: 09:13
*/
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const session = require('express-session');
const path = require('path');
const helmet = require('helmet');
const cors = require('cors');
const auth = require('./security/auth');
2020-05-19 09:05:04 +00:00
const app = express();
require('dotenv').config();
const serverPort = process.env.PORT || 8120;
2020-05-19 09:05:04 +00:00
const sitePath = 'dist';
2020-05-19 09:05:04 +00:00
2020-05-19 09:22:27 +00:00
app.use(cors());
app.use(helmet());
2020-05-19 09:05:04 +00:00
app.use(session({
'secret': 'Z4hc5.64X1e',
'resave': true,
'saveUninitialized': true
}));
app.get('/', (request, response) => {
if (request.session.auth)
response.sendFile(path.join(`${__dirname}/dist/index.html`));
else
response.sendFile(path.join(`${__dirname}/security/login.html`));
});
2020-05-19 09:05:04 +00:00
app.use(express.static(path.join(__dirname, sitePath)));
// parse requests of content-type - application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ 'extended': true }));
// parse requests of content-type - application/json
app.use(bodyParser.json());
app.post('/auth', auth.auth);
2020-05-19 09:05:04 +00:00
require('./routes/jobs.route')(app);
2020-05-25 13:51:52 +00:00
require('./routes/apply.route')(app);
2020-05-19 09:05:04 +00:00
app.listen(serverPort, () => {
console.log(`Server is listening on port ${serverPort}`);
});
((() => {
console.log('Job Server started');
// doJob();
})());