2013-04-18 14:34:02 -04:00
|
|
|
'use strict';
|
2013-04-01 17:23:25 -04:00
|
|
|
|
|
|
|
var express = require('express'),
|
2013-04-07 17:16:03 -04:00
|
|
|
port, app, dev;
|
2013-04-01 17:23:25 -04:00
|
|
|
|
2013-04-09 04:33:03 -04:00
|
|
|
port = process.env.PORT || 8585;
|
|
|
|
dev = (process.argv[2] === '--dev');
|
2013-04-07 17:16:03 -04:00
|
|
|
app = express();
|
2013-04-01 17:23:25 -04:00
|
|
|
|
|
|
|
// Server setup
|
|
|
|
app.configure(function() {
|
2013-04-20 08:59:53 -04:00
|
|
|
app.use(express.compress());
|
|
|
|
|
2013-04-06 10:45:53 -04:00
|
|
|
if (dev) {
|
|
|
|
// serve test files in development mode
|
2013-04-07 17:16:03 -04:00
|
|
|
console.log(' > Starting in development mode ...');
|
2013-04-06 10:45:53 -04:00
|
|
|
app.use(express['static'](__dirname + '/test'));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// activate content security policy for production
|
2013-04-01 17:23:25 -04:00
|
|
|
app.use(function(req, res, next) {
|
2013-04-20 08:59:53 -04:00
|
|
|
res.set('Content-Security-Policy', "default-src 'self'; script-src 'self' 'unsafe-eval'; connect-src *; object-src 'none'; style-src 'self' 'unsafe-inline'");
|
|
|
|
res.set('X-Content-Security-Policy', "default-src *; script-src 'self' 'unsafe-eval'; options eval-script; object-src 'none'; style-src 'self' 'unsafe-inline'");
|
|
|
|
res.set('X-WebKit-CSP', "default-src 'self'; script-src 'self' 'unsafe-eval'; connect-src *; object-src 'none'; style-src 'self' 'unsafe-inline'");
|
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
return next();
|
|
|
|
});
|
|
|
|
}
|
2013-04-06 10:24:28 -04:00
|
|
|
|
2013-04-01 17:23:25 -04:00
|
|
|
app.use(express['static'](__dirname + '/src'));
|
|
|
|
});
|
|
|
|
|
|
|
|
// start server
|
|
|
|
app.listen(port);
|
2013-04-07 17:16:03 -04:00
|
|
|
console.log(' > listening on http://localhost:' + port);
|