-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
75 lines (65 loc) · 1.84 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
'use strict';
var connect = require('connect')
, path = require('path')
, app = connect()
, config = require('./config')
;
function init(Db) {
var serveStatic = require('serve-static')
;
config.apiPrefix = config.apiPrefix || '/api';
if (!connect.router) {
connect.router = require('connect_router');
}
app.api = function (path, fn) {
if (!fn) {
fn = path;
path = "";
}
app.use(config.apiPrefix + path, fn);
return app;
};
app
//.use(require('morgan')())
.use(require('errorhandler')({ dumpExceptions: true, showStack: true }))
.use(require('./lib/connect-shims/query')())
.use(require('body-parser').json({
strict: true // only objects and arrays
, inflate: true
, limit: 100 * 1024
, reviver: undefined
, type: 'json'
, verify: undefined
}))
.use(require('body-parser').urlencoded({
extended: true
, inflate: true
, limit: 100 * 1024
, type: 'urlencoded'
, verify: undefined
}))
.use(require('compression')())
.use(require('./lib/connect-shims/send'))
//.use(express.router)
;
app
.use(connect.router(require('./lib/bitcrypt').create(app, config, Db).route))
;
//
// Generic Template API
//
app
//.use(require('connect-jade')({ root: __dirname + "/views", debug: true }))
.use(serveStatic(path.join(__dirname, 'priv', 'public')))
//.use(serveStatic(path.join(__dirname, 'dist')))
//.use(serveStatic(path.join(__dirname, '.tmp', 'concat')))
.use(serveStatic(path.join(__dirname, 'app')))
.use(serveStatic(path.join(__dirname, '.tmp')))
;
}
module.exports = app;
module.exports.create = function () {
config.knexInst = require('./lib/knex-connector').create(config.knex);
require('./lib/bookshelf-models').create(config.knexInst).then(init);
};
module.exports.create();