-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (45 loc) · 1.16 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var fs = require('fs');
var logger = require('koa-logger');
var koa = require('koa');
var app = koa();
//extend middleware
var bodyParser = require('koa-bodyparser');
var mongo = require('./lib/mongo');
var mysql = require('./lib/mysql');
var render = require('./lib/render');
// config
var config = require('./config/config');
// middleware
app.use(logger());
app.use(bodyParser());
app.use(render);
app.use(mongo(config.database.mongo));
app.use(mysql(config.database.mysql));
// handlers
var handlers = ['index', 'sign', 'vine'];
for (var h of handlers) {
var routes = require('./handler/' + h).routes;
for(var r of routes){
app.use(r);
}
};
// listen
/*
todo: use unix socket to nginx proxy_pass
1. When the server process have been exit and then delete the .sock file √
2. Use same nginx premission user start server process √
3. Use cli extend argument transfer .sock file path to app.js
*/
var socket = config.socket
var exist = true;
try{
fs.accessSync(socket);
}catch(err){
if(err.code == 'ENOENT')
exist = false;
}
if(exist)
fs.unlinkSync(socket);
app.listen(socket);
fs.chown(socket, 33, 33);
console.log('listening on socket: ' + socket);