-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
66 lines (55 loc) · 1.79 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
// Load express framework and http server
const express = require('express');
const app = express();
const http = require('http').Server(app);
const ejs = require('ejs');
const helmet = require('helmet');
var fs = require("fs");
const service = require('./lib/rest.js');
app.use('/assets', express.static('assets'));
app.set('view engine', 'ejs');
// app.use(helmet());
app.use(
helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'", "https://code.jquery.com", "https://cdnjs.cloudflare.com", "https://stackpath.bootstrapcdn.com"],
styleSrc: ["'self'", "fonts.googleapis.com", "'unsafe-inline'", "https://stackpath.bootstrapcdn.com"]
}
},
})
);
app.set('views', __dirname + '/views');
// Configuration variables
var port = 3000;
/**
* Main page using boostrap
*/
app.get('/', function (req, res) {
res.render('index', { title: 'Jumbotron | Home' });
});
/**
* API Calls from Library
*/
app.get('/api/:apiCall', function(req, res, next) {
let args = {apiCall: req.params.apiCall};
service.apiCall(args, (function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
res.status(response && response.statusCode || 500);
if(error) {
res.send(error);
next();
}
else {
res.send(body);
next();
}
}));
});
// Create server on port 3000
http.listen(port, function () {
console.log('version 1.0.0 listening on *:' + port);
});