-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (36 loc) · 1.06 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
#!/usr/bin/env node
var bunyan = require('bunyan');
var data = require('level-userdb')
var domain = require('domain')
var net = require('net')
var multilevel = require('multilevel')
var ui = require('optimist')
.usage('Usage: $0 -d [database] -a [address] -p [port] ')
.alias('d', 'database')
.describe('d', 'Path to database location')
.default('d', './level-userdb.db')
.alias('a', 'address')
.default('a', '0.0.0.0')
.describe('a', 'address to listen on')
.alias('p', 'port')
.describe('p', 'port to listen on')
.default('p', 9998)
.alias('h', '--help')
var argv = ui.argv
var log = bunyan.createLogger({name: "level-userdb-server"});
if (argv.h) {
ui.showHelp()
process.exit(1)
}
var d = domain.create()
d.on('error', function(err) {
log.error(err)
})
d.run(function() {
var db = data(argv.database)
// Wrap level-userdb with multilevel server
net.createServer(function (c) {
c.pipe(multilevel.server(db)).pipe(c)
}).listen(argv.port, argv.address)
log.info("level-userdb-server listening on %s:%s", argv.address, argv.port)
})