mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
29 lines
867 B
TypeScript
29 lines
867 B
TypeScript
/// <reference path="connect-timeout.d.ts" />
|
|
/// <reference path="../body-parser/body-parser.d.ts" />
|
|
/// <reference path="../cookie-parser/cookie-parser.d.ts" />
|
|
/// <reference path="../express/express.d.ts" />
|
|
|
|
import * as express from "express";
|
|
import timeout from "connect-timeout";
|
|
import * as bodyParser from "body-parser";
|
|
import * as cookieParser from "cookie-parser";
|
|
|
|
// example of using this top-level; note the use of haltOnTimedout
|
|
// after every middleware; it will stop the request flow on a timeout
|
|
var app = express();
|
|
app.use(timeout("5s", { respond: false }));
|
|
app.use(bodyParser());
|
|
app.use(haltOnTimedout);
|
|
app.use(cookieParser());
|
|
app.use(haltOnTimedout);
|
|
|
|
// Add your routes here, etc.
|
|
|
|
function haltOnTimedout(req: express.Request, res: express.Response, next: Function) {
|
|
if (!req.timedout) {
|
|
next();
|
|
}
|
|
}
|
|
|
|
app.listen(3000);
|