-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
116 lines (96 loc) · 2.38 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const helmet = require('helmet');
var hsts = require('hsts');
const path = require('path');
var xssFilter = require('x-xss-protection');
var nosniff = require('dont-sniff-mimetype');
const request = require('request');
const app = express();
app.use(cors());
app.use(express.static('assets'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.disable('x-powered-by');
app.use(xssFilter());
app.use(nosniff());
app.set('etag', false);
app.use(
helmet({
noCache: true
})
);
app.use(
hsts({
maxAge: 15552000 // 180 days in seconds
})
);
app.use(
express.static(path.join(__dirname, 'dist/trexis-racing'), {
etag: false
})
);
app.get('/api/members', (req, res) => {
request('http://localhost:3000/members', (err, response, body) => {
if (response.statusCode <= 500) {
res.send(body);
}
});
});
app.get('/api/teams', (req, res) => {
request('http://localhost:3000/teams', (err, response, body) => {
if (response.statusCode <= 500) {
res.send(body);
}
});
});
app.get('/api/members/:id', (req, res) => {
let options = {
url: 'http://localhost:3000/members/' + req.params.id
};
request.get(options, (err, response, body) => {
if (response.statusCode <= 500) {
res.send(body);
}
});
});
// Submit Form!
app.post('/api/addMember', (req, res) => {
let options = {
url: 'http://localhost:3000/members',
form: req.body
};
request.post(options, (err, response, body) => {
if (response.statusCode <= 500) {
res.send(body);
}
});
});
app.put('/api/members/:id', (req, res) => {
let options = {
url: 'http://localhost:3000/members/' + req.params.id,
form: req.body
};
request.put(options, (err, response, body) => {
if (response.statusCode <= 500) {
res.send(body);
}
});
});
app.delete('/api/members/:id', (req, res) => {
let options = {
url: 'http://localhost:3000/members/' + req.params.id,
};
request.delete(options, (err, response, body) => {
if (response.statusCode <= 500) {
res.send(body);
}
});
});
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/trexis-racing/index.html'));
});
app.listen('8000', () => {
console.log('Vrrrum Vrrrum! Server starting!');
});