jobscraper/server/server.js
Martin Donnelly b45f389f97 * Detail shows highlight for applied
* UI structured a little diferently
* Read All Items button and mechanism
2020-05-26 13:17:20 +01:00

62 lines
1.3 KiB
JavaScript

/**
* 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');
const app = express();
require('dotenv').config();
const serverPort = process.env.PORT || 8120;
const sitePath = 'dist';
app.use(cors());
app.use(helmet());
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`));
});
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);
require('./routes/jobs.route')(app);
require('./routes/apply.route')(app);
app.listen(serverPort, () => {
console.log(`Server is listening on port ${serverPort}`);
});
((() => {
console.log('Job Server started');
// doJob();
})());