-
Notifications
You must be signed in to change notification settings - Fork 73
/
server.js
72 lines (66 loc) · 2.36 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
"use strict";
const express = require('express');
const morgan = require('morgan');
const body_parser = require('body-parser');
const method_override = require('method-override');
const log = require('./helpers/log');
const tres = require('./helpers/tres');
const cors = require('./helpers/cors');
const turtl_auth = require('./helpers/auth');
const config = require('./helpers/config');
const error = require('./helpers/error');
const fs = require('fs');
const plugins = require('./helpers/plugins');
var app = express();
app.disable('etag');
app.use(method_override('_method'));
app.use(cors);
app.use(body_parser.json({strict: false, limit: '24mb'}));
app.use(body_parser.urlencoded({extended: true, limit: '4mb'}));
app.use(morgan(':remote-addr ":method :url" :status :res[content-length]', {
stream: { write: function(message, _enc) { log.info(message.slice(0, -1)); } }
}));
app.use(turtl_auth.verify);
// welcome route
app.get('/', function(req, res) {
tres.send(res, {greeting: "Hi."});
});
// load controllers
['users', 'sync', 'spaces', 'files', 'feedback', 'errlog', 'cla', 'bookmarking', 'health']
.forEach(function(con) {
// only load bookmarking controller if we REALLY specify we want it
if(con == 'bookmarking' && config.app.enable_bookmarker_proxy != 'I UNDERSTAND THIS VIOLATES THE PRIVACY OF MY USERS') {
return;
}
log.info('Loading controller: '+con);
var controller = require('./controllers/'+con);
controller.route(app);
});
// load plugins
try {
var plugin_dir = config.plugins.plugin_location || './plugins'
var plugin_list = fs.readdirSync(plugin_dir);
} catch(e) {
log.info('Problem loading plugins: ', e);
}
plugin_list.forEach(function(plugin) {
if(plugin[0] == '.') return;
if(plugin == 'node_modules') return;
var stats = fs.lstatSync(plugin_dir+'/'+plugin);
if(!stats.isDirectory()) return;
log.info('Loading plugin: '+plugin);
var loader = require(plugin_dir+'/'+plugin+'/main.js');
var plugin_config = config.plugins[plugin];
loader.load(plugins.register.bind(plugins, plugin), plugin_config, {
app: app,
auth: turtl_auth,
plugins: plugins,
});
});
if (config.server.host) {
app.listen(config.server.port, config.server.host);
log.info('Listening for turtls on IP '+config.server.host+', port '+config.server.port+'...');
} else {
app.listen(config.server.port);
log.info('Listening for turtls on port '+config.server.port+'...');
}