-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
86 lines (70 loc) · 2 KB
/
server.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
78
79
80
81
82
83
84
85
86
var express = require('express'),
/**
* Instantiate the unique Express instance
*/
app = module.exports = express();
var crypto = require('crypto');
GLOBAL.crypto = crypto;
/**
* @type {Express}
*
* The Singleton of Express app instance
*/
GLOBAL.app = app;
fs = require('fs');
eval(fs.readFileSync('settings.json', 'ascii'));
var mysql = require('mysql');
var connection_r = mysql.createConnection({
host : settings.mysql.host,
user : settings.mysql.user,
password : settings.mysql.password,
port : settings.mysql.port,
database : settings.mysql.database
})
var connection_rw = mysql.createConnection({
host : settings.mysql.host,
user : settings.mysql.user_rw,
password : settings.mysql.password_rw,
port : settings.mysql.port,
database : settings.mysql.database
})
GLOBAL.connection_r = connection_r;
GLOBAL.connection_rw = connection_rw;
// Configuration
app.configure(function() {
app.use(express.logger({format: 'dev'}));
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: 'my0verHudgeC00k13S3cretPa55w0rd0fTh3D3athWithBatman', cookie : { maxAge : 1000 * 60 * 20 } }));
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
app.engine('html', require('ejs').renderFile);
});
app.configure('development', function() {
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function() {
app.use(express.errorHandler());
});
app.param(function(name, fn){
if(fn instanceof RegExp){
return function(req, res, next, val){
var captures;
if(captures = fn.exec(String(val))){
req.params[name] = captures;
next();
}else{
next('route');
}
}
}
});
app.param('id', /^\d+$/);
// Routes
require('./routes.js');
app.listen(8010);
console.log('Its is on !');
//console.log('Express server listening on port %d in %s mode',
// app.address().port, app.settings.env);