mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
Add definition for "connect-timeout".
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/// <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 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);
|
||||
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
// Type definitions for connect-timeout
|
||||
// Project: https://github.com/expressjs/timeout
|
||||
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user