-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (31 loc) · 911 Bytes
/
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
/**
* Fast Dynamic HTTP Server
* Dynamic HTTP server that automatically handles URL to local resource path and content-type headers
*
* Dynamically composes a response that automatically handles:
* - Request URL local directory path.
* (ex. "http://exampe.com/fag.html" will become "./fag.html")
*
* Polymorphic Content-Type header.
* - reduces resource extension.
* - "http://exampe.com/style.css" -> "text/css"
*/
const {createServer} = require("http");
const {dispatch} = require("./dispatcher.js");
const config = {
port: 8080,
host: "127.0.0.1"
};
const server = createServer((req, res) => {
try {
dispatch(req, res);
} catch(err) {
console.error(err);
}
});
server.listen(config.port, config.host, (err) => {
if (err) {
console.error(err);
}
console.log(`server running on port http://${config.host}:${config.port}/`);
});