@@ -13,58 +13,60 @@ feature.
13
13
14
14
Take the following example server:
15
15
16
- var middleware = require('./middleware');
17
-
18
- var app = middleware.createServer();
19
-
20
- app.use(function (req, res, next) {
21
- res.write('a');
22
- next();
23
- });
24
-
25
- app.use('/hello', function (req, res, next) {
26
- res.write('b');
27
- next();
28
- });
29
-
30
- app.use(function (req, res, next) {
31
- res.write('c');
32
- next();
33
- });
34
-
35
- app.use('/hello', function (req, res) {
36
- res.end('hello');
37
- });
38
-
39
- app.use('/goodbye', function (req, res) {
40
- res.end('goodbye');
41
- });
42
-
43
- app.use(function (req, res) {
44
- res.end('end');
45
- });
46
-
47
- app.listen(3000, function () {
48
- console.log('Server started at 3000');
49
- });
50
-
16
+ ``` js
17
+ var middleware = require ( ' ./middleware ' );
18
+ var app = middleware .createServer ();
19
+
20
+ app .use (function (req , res , next ) {
21
+ res .write (' a' );
22
+ next ();
23
+ });
24
+
25
+ app .use (' /hello' , function (req , res , next ) {
26
+ res .write (' b' );
27
+ next ();
28
+ });
29
+
30
+ app .use (function (req , res , next ) {
31
+ res .write (' c' );
32
+ next ();
33
+ });
34
+
35
+ app .use (' /hello' , function (req , res ) {
36
+ res .end (' hello' );
37
+ });
38
+
39
+ app .use (' /goodbye' , function (req , res ) {
40
+ res .end (' goodbye' );
41
+ });
42
+
43
+ app .use (function (req , res ) {
44
+ res .end (' end' );
45
+ });
46
+
47
+ app .listen (3000 , function () {
48
+ console .log (' Server started at 3000' );
49
+ });
50
+ ```
51
51
52
52
Your micro-framework will implement at least 3 methods:
53
53
54
- * ` createServer() `
55
- * ` use(handler) `
56
- * ` listen(port, callback) `
54
+ + ` createServer() `
55
+ + ` use(handler) `
56
+ + ` listen(port, callback) `
57
57
58
58
The above server will run as you would expect:
59
59
60
- * ` GET /hello ` would return ` abchello `
61
- * ` GET /goodbye ` would return ` acgoodbye `
62
- * ` GET / ` would return ` acend `
60
+ + ` GET /hello ` would return ` abchello `
61
+ + ` GET /goodbye ` would return ` acgoodbye `
62
+ + ` GET / ` would return ` acend `
63
63
64
64
Do you have what it takes?
65
65
66
66
67
67
## Usage
68
68
69
- $ npm install
70
- $ npm test
69
+ ``` sh
70
+ $ npm install
71
+ $ npm test
72
+ ```
0 commit comments