diff --git a/connect/connect-tests.ts b/connect/connect-tests.ts new file mode 100644 index 000000000..c368a3b93 --- /dev/null +++ b/connect/connect-tests.ts @@ -0,0 +1,32 @@ +/// + +import * as http from "http"; +import * as connect from "connect"; + +const app = connect(); + +// log all requests +app.use((req, res, next) => { + console.log(req, res); + next(); +}); + +// Stop on errors +app.use((err, req, res, next) => { + if (err) { + return res.end(`Error: ${err}`); + } + + next(); +}); + +// respond to all requests +app.use((req, res) => { + 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);