forked from automenta/netjs3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
111 lines (99 loc) · 3.38 KB
/
index.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
/*
* netjs3 (forked from smallest federated wiki) : Node Server
*
* Copyright Ward Cunningham and other contributors
* Licensed under the AGPL
*/
var app, argv, cc, config, farm, getUserHome, glob, optimist, path, server;
path = require('path');
optimist = require('optimist');
cc = require('config-chain');
glob = require('glob');
farm = require('./farm');
server = require('./server');
getUserHome = function () {
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
};
argv = optimist.usage('Usage: $0').options('url', {
alias: 'u',
describe: 'Important: Your server URL, used as Persona audience during verification'
}).options('port', {
alias: 'p',
describe: 'Port'
}).options('data', {
alias: 'd',
describe: 'location of flat file data'
}).options('root', {
alias: 'r',
describe: 'Application root folder'
}).options('farm', {
alias: 'f',
describe: 'Turn on the farm?'
}).options('home', {
describe: 'The page to go to instead of index.html'
}).options('host', {
alias: 'o',
describe: 'Host to accept connections on, falsy == any'
}).options('id', {
describe: 'Set the location of the open id file'
}).options('database', {
describe: 'JSON object for database config'
}).options('neighbors', {
describe: 'comma separated list of neighbor sites to seed'
}).options('autoseed', {
describe: 'Seed all sites in a farm to each other site in the farm.',
boolean: true
}).options('allowed', {
describe: 'comma separated list of allowed host names for farm mode.'
}).options('uploadLimit', {
describe: 'Set the upload size limit, limits the size page content items, and pages that can be forked'
}).options('test', {
boolean: true,
describe: 'Set server to work with the rspec integration tests'
}).options('help', {
alias: 'h',
boolean: true,
describe: 'Show this help info and exit'
}).options('config', {
alias: 'conf',
describe: 'Optional config file.'
}).options('version', {
alias: 'v',
describe: 'Optional config file.'
}).argv;
config = cc(argv, argv.config, 'config.json', path.join(__dirname, '..', 'config.json'), cc.env('wiki_'), {
root: __dirname, //path.dirname(require.resolve('wiki-server')),
home: 'index',
packageDir: path.resolve(path.join(__dirname, 'node_modules'))
}).store;
if (argv.help) {
optimist.showHelp();
} else if (argv.version) {
console.log('core: ' + require('./package').version);
glob('wiki-plugin-*', {
cwd: config.packageDir
}, function (e, plugins) {
return plugins.map(function (plugin) {
return console.log(plugin + ': ' + require(plugin + '/package').version);
});
});
} else if (argv.test) {
console.log("WARNING: Server started in testing mode, other options ignored");
server({
port: 33333,
data: path.join(argv.root, 'spec', 'data')
});
} else if (config.farm) {
console.log('netjs3 cluster: navigate to a specific server to start it.');
farm(config);
} else {
argv.db = 'netention';
argv.dbpath = 'db';
var db = require('./server/p2pdb')(argv, function (db) {
app = server(config, db);
console.log('listening..');
var serv = app.listen(app.startOpts.port, app.startOpts.host);
console.log("netjs3 on:", app.startOpts.port, "in mode:", app.settings.env);
return app.emit('running-serv', serv);
});
}