-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (27 loc) · 788 Bytes
/
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
var http = require("http"),
request = require("./lib/request"),
response = require("./lib/response"),
findHandler = require("./lib/router").findHandler,
Router = require("./lib/router").Router,
middleware = require("./lib/middleware")(),
notFound = require("./lib/not-found");
var server = http.createServer((req, res) => {
request(req);
response(res);
middleware.run(req, res);
var handler = findHandler(req);
if(handler) {
handler(req, res);
} else {
notFound(req, res);
}
});
function listen(port) {
server.listen(port, () => console.log("Server running on port " + port));
}
module.exports = function() {
var router = Router();
router.listen = listen;
router.use = middleware.use;
return router;
}