-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
142 lines (108 loc) · 3.64 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Module dependencies.
*/
var express = require('express')
, util = require('util')
, MysqlDriver = require("./lib/mysql_driver")
, mysql
, os = require('os')
, config = require('./lib/config')
, db_config = config.getDbConfig()
, connectRails = require('./lib/connect-rails')
, helper = require('helper')
, io = require('socket.io')
, fs = require('fs')
, host = "127.0.0.1"
, db_logging
, parseCookie = require('connect').utils.parseCookie
//, recoms = require('recoms')
, mongoose = require('mongoose')
, db = mongoose.createConnection('localhost', 'test')
, Schema = mongoose.Schema
var app = module.exports = express.createServer()
// Setup mysql connection
app.configure('development', function () {
db_config = db_config.development
db_logging = true
app.set('server_url', "http://localhost:8000")
app.use(express.static(__dirname + '/public', { maxAge: 0}));
//app.use(require('browserify')({require:__dirname + '/public/js/dash_app.js', mount: "/dash.js"}))
app.use(express.errorHandler({dumpExceptions: true, showStack: true }))
});
app.configure('production', function () {
// generate pid file
fs.writeFile( '/recjs/shared/pids/node.pid'
, process.pid + "\n"
, function (err) {
if (err) throw err;
}
)
host = "127.0.0.1";
db_config = db_config.production;
db_logging = false;
app.set('server_email', "Recjs <[email protected]>")
app.set('server_url', "http://recjs.com")
var oneYear = 31557600000;
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
app.use(express.errorHandler());
});
app.configure('test', function () {
db_config = db_config.test;
db_logging = true;
app.set('server_email', "Recjs Test <[email protected]>")
app.set('server_url', "http://localhost:8000")
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
})
// 'recjs_development', 'root', null
mysql = new MysqlDriver( db_config.database
, db_config.username
, db_config.password
, {logging: db_logging}
)
//app.db = mysql;
app.db = db;
app.Schema = Schema;
// mysql.user = app.settings.db_config.username;
// mysql.password = app.settings.db_config.password;
//
// mysql.connect();
// mysql.query('USE ' + app.settings.db_config.database);
// app.set('mysql', mysql);
// Configuration
app.configure(function () {
// Bind views
app.set('views', __dirname + '/app/views');
// app.set('view engine', 'ejs');
app.set('view engine', 'jade');
// uploads files by default into /tmp folder
app.use(express.bodyParser({keepExtensions: true, uploadDir: __dirname + "/tmp"}))
//app.use(express.bodyParser())
app.use(express.methodOverride());
app.use(express.cookieParser());
// adds database to request
app.use(connectRails.database(mysql));
// app.use(express.session({ secret: 'secret here' }));
app.use(app.router);
});
// add special classes to application namespace
app.helper = helper;
// app.configure(function () {
// app.use(rails.session)
// app.use(rails.mysql)
// })
// Boot all models
// var models = require(__dirname + "/app/models/user");
// models.init(mysql);
// Start recommendation engine and assign it to app
//app.recoms = recoms
// Bootstrap routes and controllers
// routes are included inside controllers
var boot = require(__dirname + '/config/boot');
global.mysql = mysql;
boot.start(app);
app.listen(9000, host, function () {
console.log( "Express server listening on port %d in %s mode"
, app.address().port
, app.settings.env
)
});