-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
61 lines (46 loc) · 1.73 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require('express');
const compression = require('compression');
const path = require('path');
const chalk = require('chalk');
const bodyParser = require('body-parser');
const ms = require('ms');
const helmet = require('helmet');
const projects = require('./content/project-data');
const overview = require('./content/overview-page');
const portfolio = require('./content/portfolio-page');
const skills = require('./content/skills-page');
const pingController = require('./ping/ping.controller');
const app = express();
app.use(bodyParser.json())
app.use(compression());
app.use(helmet());
let port = process.env.PORT || 4200;
const pingPrimary = true;
const pingSecondary = true;
app.use(express.static(path.join(__dirname, 'dist'), {maxAge: ms('1y')}));
app.get('/content', (req, res) => {
res.setHeader('Cache-Control', 'public, max-age=86400');
res.status(200).send({projects, overview, portfolio, skills});
});
app.post('/ping', (req, res) => {
const {type} = req.body;
console.log(type)
if (type === 'primary' && pingPrimary) {
pingController.pingPrimaryProjects();
res.status(200).send(JSON.stringify('Primary Projects Pinged'));
} else if (type === 'secondary' && pingSecondary) {
pingController.pingSecondaryProjects();
res.status(200).send(JSON.stringify('Secondary Projects Pinged'));
} else {
res.status(200).send(JSON.stringify('Ping service is switched off'));
}
});
app.get('/alistair-willis', (req, res) => {
res.status(200).sendFile(path.join(__dirname, 'alistair-willis-CV-2018.pdf'));
});
app.get('/*', (req, res) => {
res.status(200).sendFile(path.join(__dirname, 'dist/index.html'));
});
app.listen(port, () => {
console.log(chalk.green('API Running on Port ' + port));
});