diff --git a/connect-timeout/connect-timeout-tests.ts b/connect-timeout/connect-timeout-tests.ts new file mode 100644 index 000000000..283ee2679 --- /dev/null +++ b/connect-timeout/connect-timeout-tests.ts @@ -0,0 +1,28 @@ +/// +/// +/// +/// + +import express = require("express"); +import timeout = require("connect-timeout"); +import bodyParser = require("body-parser"); +import cookieParser = require("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, res, next) { + if (!req.timedout) { + next(); + } +} + +app.listen(3000); diff --git a/connect-timeout/connect-timeout.d.ts b/connect-timeout/connect-timeout.d.ts new file mode 100644 index 000000000..8b7ff2879 --- /dev/null +++ b/connect-timeout/connect-timeout.d.ts @@ -0,0 +1,36 @@ +// Type definitions for connect-timeout +// Project: https://github.com/expressjs/timeout +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module Express { + export interface Request { + /** + * @summary Clears the timeout on the request. + */ + clearTimeout(): void; + + /** + * + * @return {boolean} true if timeout fired; false otherwise. + */ + timedout(event: string, message: string): boolean; + } +} + +declare module "connect-timeout" { + import express = require("express"); + + interface TimeoutOptions extends Object { + /** + * @summary Controls if this module will "respond" in the form of forwarding an error. + * @type {boolean} + */ + respond: boolean; + } + + function timeout(timeout: string, options?: TimeoutOptions): express.RequestHandler; + export = timeout; +}