-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (36 loc) · 1.24 KB
/
app.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
var BlessYou = require('./server.js')
,yargs= require('yargs')
,argv = args()
,fs = require('fs')
,Cache = require('./cache.js')
,Memcached = require('memcached')
,l = console.log;
function args() {
return yargs.usage("Usage: $0 --port=<port> [--host=<host-ip>] [--pid-file=path]")
.describe('port', 'tcp port to run the http server on.')
.demand('port')
.describe('host', 'tcp host to accept connections from.')
.default('host', '127.0.0.1')
.describe('memcache-server', 'i.e. 127.0.0.1:11211')
.describe('memcache-expire-time', 'expire time in seconds for compiled css stored in memcache')
.describe('pid-file', 'file path to save the current pid in')
.argv
}
function getCacheFromArgs() {
if (argv['memcache-server']) {
const config = {
memcache: new Memcached(argv['memcache-server']),
expireTime: argv['memcache-expire-time']
}
l("Using memcache");
return Cache(config);
}
}
argv.cache = getCacheFromArgs()
var server = new BlessYou(argv);
server.listen(argv.port, argv.host, function() {
l("http server listening on: " + argv.host + ":" + argv.port);
});
if (argv['pid-file']) {
fs.writeFileSync(argv['pid-file'], process.pid)
}