1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-25 10:22:18 -05:00

cleanup server.js

This commit is contained in:
Tankred Hase 2013-04-06 16:45:53 +02:00
parent 7ae1a57888
commit 2480ac0036

View File

@ -6,21 +6,16 @@ var express = require('express'),
fs = require('fs'),
port, app, prot, dev;
// set port
if (process.argv[2]) {
port = process.argv[2];
} else {
port = 8585;
}
port = (process.argv[2]) ? process.argv[2] : 8585;
dev = (process.argv[3] === '--dev');
if (process.argv[3] === '--dev') {
if (dev) {
// development server
dev = true;
console.log(' > Starting in development mode ...');
prot = 'http';
app = express();
} else {
// production server
dev = false;
prot = 'https';
app = express({
ca: fs.readFileSync('./ssl/sub.class1.server.ca.pem'),
@ -31,8 +26,12 @@ if (process.argv[3] === '--dev') {
// Server setup
app.configure(function() {
// active content security policy for production
if (!dev) {
if (dev) {
// serve test files in development mode
app.use(express['static'](__dirname + '/test'));
} else {
// activate content security policy for production
app.use(function(req, res, next) {
var csp = "script-src 'self' 'unsafe-eval'; object-src 'none'; style-src 'self' 'unsafe-inline'";
res.set('Content-Security-Policy', csp);
@ -42,10 +41,6 @@ app.configure(function() {
});
}
if (dev) {
app.use(express['static'](__dirname + '/test'));
}
app.use(express['static'](__dirname + '/src'));
});