-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.js
77 lines (64 loc) · 2.21 KB
/
index.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
var http = require('http');
var https = require('https');
var fs = require('fs');
var path = require('path');
var util = require('gulp-util');
var connect = require('connect');
var serveStatic = require('serve-static');
module.exports = function (config) {
config || (config = {});
return function () {
var app = connect();
if (typeof config === 'string') {
config = {
root: [config]
};
}
if (Array.isArray(config)) {
config = {
root: config
};
}
if (!config.root) {
config.root = ['.'];
}
if (!config.hostname) {
config.hostname = 'localhost';
}
if (typeof config.root === 'string') {
config.root = [config.root];
}
if (!config.middlewares) {
config.middlewares = [];
}
if (config.middleware) {
config.middlewares.push(config.middleware);
}
config.middlewares.forEach(function(middleware) {
app.use(middleware);
});
config.root.forEach(function (path) {
app.use(serveStatic(path));
});
if (!config.port) {
config.port = 3000;
}
var serverInitFunction = function () {
var addr = server.address();
var address = addr.address;
var port = addr.port;
var scheme = 'http' + (config.https ? 's' : '');
util.log(util.colors.blue('Server started at ' + scheme + '://' + address + ':' + port));
};
if (config.https) {
var opts = {
key: fs.readFileSync(config.https.key || path.join(__dirname, 'ssl/localhost.key')),
cert: fs.readFileSync(config.https.cert || path.join(__dirname, 'ssl/localhost.pem')),
ciphers: config.https.ciphers || 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA' // Intermediat Ciphers from https://wiki.mozilla.org/Security/Server_Side_TLS
};
var server = https.createServer(opts, app).listen(config.port, config.hostname, serverInitFunction);
} else {
var server = http.createServer(app).listen(config.port, config.hostname, serverInitFunction);
}
};
};