forked from ltonetwork/mongodb-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
55 lines (45 loc) · 1.13 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
/*
server.js
mongodb-rest
Created by Tom de Grunt on 2010-10-03.
Copyright (c) 2010 Tom de Grunt.
This file is part of mongodb-rest.
*/
var fs = require("fs"),
sys = require("sys"),
express = require('express');
var config = { "db": {
'port': 27017,
'host': "localhost"
},
'server': {
'port': 3000,
'address': "0.0.0.0"
},
'flavor': "regular",
'debug': true
};
var app = module.exports.app = express.createServer();
try {
config = JSON.parse(fs.readFileSync(process.cwd()+"/config.json"));
} catch(e) {
// ignore
}
module.exports.config = config;
app.configure(function(){
app.use(express.bodyParser());
app.use(express.static(process.cwd() + '/public'));
app.use(express.logger());
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
if (config.accessControl){
var accesscontrol = require('./lib/accesscontrol');
app.use(accesscontrol.handle);
}
});
require('./lib/main');
require('./lib/command');
require('./lib/rest');
if(!process.argv[2] || !process.argv[2].indexOf("expresso")) {
app.listen(config.server.port, config.server.address);
}