Skip to content

Commit 089c2af

Browse files
committed
Connectの仕組み
close #57
1 parent eadf221 commit 089c2af

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/connect/connect-trace-example.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"use strict";
2+
import errorHandler from "./errorHandler";
3+
import hello from "./hello";
4+
import nosniff from "./nosniff";
5+
import assert from "assert";
6+
import connect from "connect";
7+
import http from "http";
8+
import fetch from "node-fetch";
9+
10+
const responseText = "response text";
11+
let app = connect();
12+
// add Error handling
13+
app.use(errorHandler());
14+
// add "X-Content-Type-Options" to response
15+
app.use(nosniff());
16+
// respond to all requests
17+
app.use(hello(responseText));
18+
19+
//create node.js http server and listen on port
20+
let server = http.createServer(app).listen(3000, request);
21+
22+
function request() {
23+
let closeServer = server.close.bind(server);
24+
fetch("http://localhost:3000")
25+
.then(res => res.text())
26+
.then(text => {
27+
assert.equal(text, responseText);
28+
server.close();
29+
})
30+
.catch(console.error.bind(console))
31+
.then(closeServer, closeServer);
32+
}

0 commit comments

Comments
 (0)