-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
97 lines (81 loc) · 2.53 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
/* global console */
var path = require('path');
var express = require('express');
var helmet = require('helmet');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var Moonboots = require('moonboots-express');
var compress = require('compression');
var config = require('getconfig');
var semiStatic = require('semi-static');
var serveStatic = require('serve-static');
var app = express();
// a little helper for fixing paths for various environments
var fixPath = function (pathString) {
return path.resolve(path.normalize(pathString));
};
// -----------------
// Configure express
// -----------------
app.use(compress());
app.use(serveStatic(fixPath('public')));
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// in order to test this with spacemonkey we need frames
if (!config.isDev) {
app.use(helmet.xframe());
}
app.use(helmet.xssFilter());
app.use(helmet.nosniff());
app.set('views', fixPath('templates'));
app.set('view engine', 'handlebars');
// -----------------
// Set up our little demo API
// -----------------
var api = require('./fakeApi');
app.get('/api/people', api.list);
app.get('/api/people/:id', api.get);
app.delete('/api/people/:id', api.delete);
app.put('/api/people/:id', api.update);
app.post('/api/people', api.add);
// -----------------
// Enable the functional test site in development
// -----------------
if (config.isDev) {
app.get('/test*', semiStatic({
folderPath: fixPath('test'),
root: '/test'
}));
}
// -----------------
// Set our client config cookie
// -----------------
app.use(function (req, res, next) {
res.cookie('config', JSON.stringify(config.client));
next();
});
// ---------------------------------------------------
// Configure Moonboots to serve our client application
// ---------------------------------------------------
new Moonboots({
moonboots: {
jsFileName: 'gulp-handlebars',
cssFileName: 'gulp-handlebars',
main: fixPath('client/app.js'),
developmentMode: config.isDev,
libraries: [
],
stylesheets: [
fixPath('public/css/bootstrap.css'),
fixPath('public/css/app.css')
],
browserify: {
debug: config.isDev
}
},
server: app
});
// listen for incoming http requests on the port as specified in our config
app.listen(config.http.port);
console.log('Gulp Handlebars is running at: http://localhost:' + config.http.port + ' Yep. That\'s pretty awesome.');