-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathws.js
34 lines (29 loc) · 775 Bytes
/
ws.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
// A simple web server that serves files off the
// current directory.
//
// Run as -
// node ws.js
//
// and visit http://localhost:9000/ws.js in your browser.
//
// Notes:
// Doesn't do directory listings. You need to know your file name.
var IO = require('../src/IO.WebServer.js');
var ws = IO.WebServer(9000);
var reportInvalidURL = IO.cond([
[{error: 'path not found'}, error('Invalid URL')],
[IO.cond.true, error('Cannot list directories.')]
]);
ws.route('/',
IO.do([
IO.catch(reportInvalidURL),
ws.serveDir('./')
]),
true);
ws.start();
function error(text) {
return IO.do([
function (err) { return err.input; },
ws.page(ws.write(text))
]);
}