mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
32 lines
748 B
TypeScript
32 lines
748 B
TypeScript
|
|
import * as http from "http";
|
|
import * as connect from "connect";
|
|
|
|
const app = connect();
|
|
|
|
// log all requests
|
|
app.use((req: http.IncomingMessage, res: http.ServerResponse, next: Function) => {
|
|
console.log(req, res);
|
|
next();
|
|
});
|
|
|
|
// Stop on errors
|
|
app.use((err: Error, req: http.IncomingMessage, res: http.ServerResponse, next: Function) => {
|
|
if (err) {
|
|
return res.end(`Error: ${err}`);
|
|
}
|
|
|
|
next();
|
|
});
|
|
|
|
// respond to all requests
|
|
app.use((req: http.IncomingMessage, res: http.ServerResponse) => {
|
|
res.end("Hello from Connect!\n");
|
|
});
|
|
|
|
//create node.js http server and listen on port
|
|
http.createServer(app).listen(3000);
|
|
|
|
//create node.js http server and listen on port using connect shortcut
|
|
app.listen(3000);
|