-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
executable file
·70 lines (50 loc) · 1.24 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
#!/usr/bin/env node
var readdir = require('fs').readdir
var OneShoot = require('oneshoot')
var finalhandler = require('finalhandler')
var minimist = require('minimist')
var recv = require('recv')
var serveStatic = require('serve-static')
var rfc4437 = require('./lib/rfc4437')
var rfc4918 = require('./lib/rfc4918')
const HOME = process.env.HOME
// Check arguments
var args = minimist(process.argv.slice(2),
{
string: 'hostname',
default:
{
hostname: '0.0.0.0',
port: 0
}
})
// Create server
var server = OneShoot(args.timeout).createServer()
// HTTP
var options =
{
dotfiles: 'allow',
onIndex: function(path)
{
var res = this.res
readdir(path, function(error, files)
{
if(error) return next(error)
res.end(files.join('\n')) // https://github.com/unbit/spockfs#readdir
})
}
}
var static = serveStatic(HOME, options)
server.on('request', function(req, res)
{
var done = finalhandler(req, res)
var symlinks = rfc4437(req, res, done)
var dav = rfc4918(req, res, symlinks)
var httpRecv = recv (req, res, dav)
static(req, res, httpRecv)
})
// Start server
server.listen(args.port, args.hostname, function()
{
process.stdout.write(JSON.stringify(this.address().port))
})