Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect: Add NextFunction for next, fix err parameter #24883

Merged
merged 1 commit into from Apr 17, 2018

Conversation

EvanHahn
Copy link
Contributor

@EvanHahn EvanHahn commented Apr 10, 2018

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: code sample, next documentation
  • Increase the version number in the header if appropriate.
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }.

@@ -17,9 +18,11 @@ declare function createServer(): createServer.Server;
declare namespace createServer {
export type ServerHandle = HandleFunction | http.Server;

type NextFunction = (err?: any) => void;
Copy link
Contributor

@mohsen1 mohsen1 Apr 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't error null | Error?

Copy link
Contributor Author

@EvanHahn EvanHahn Apr 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these are valid in Connect:

next();
next(null);
next(new Error("Something bad happened!"));
next(404);
next(true);

@typescript-bot typescript-bot added the Popular package label Apr 10, 2018
@typescript-bot
Copy link
Contributor

@typescript-bot typescript-bot commented Apr 10, 2018

@EvanHahn Thank you for submitting this PR!

🔔 @SomaticIT - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@typescript-bot typescript-bot added the Unmerged label Apr 15, 2018
@typescript-bot
Copy link
Contributor

@typescript-bot typescript-bot commented Apr 15, 2018

After 5 days, no one has reviewed the PR 😞. A maintainer will be reviewing the PR in the next few days and will either merge it or request revisions. Thank you for your patience!

@RyanCavanaugh RyanCavanaugh merged commit 23c8bbf into DefinitelyTyped:master Apr 17, 2018
1 check passed
@typescript-bot typescript-bot removed this from Merge: YSYL in Pull Request Triage Backlog Apr 17, 2018
export type NextHandleFunction = (req: http.IncomingMessage, res: http.ServerResponse, next: Function) => void;
export type ErrorHandleFunction = (err: Error, req: http.IncomingMessage, res: http.ServerResponse, next: Function) => void;
export type NextHandleFunction = (req: http.IncomingMessage, res: http.ServerResponse, next: NextFunction) => void;
export type ErrorHandleFunction = (err: any, req: http.IncomingMessage, res: http.ServerResponse, next: NextFunction) => void;
export type HandleFunction = SimpleHandleFunction | NextHandleFunction | ErrorHandleFunction;
Copy link

@geekley geekley Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EvanHahn I think that req in the callbacks should use a subtype of http.IncomingMessage which also has req.originalUrl: string.

In order to make middleware easier to write to be agnostic of the route, when the fn is invoked, the req.url will be altered to remove the route part (and the original will be available as req.originalUrl). For example, if fn is used at the route /foo, the request for /foo/bar will invoke fn with req.url === '/bar' and req.originalUrl === '/foo/bar'.
-- https://www.npmjs.com/package/connect#appuseroute-fn

Copy link
Contributor Author

@EvanHahn EvanHahn Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks right to me. Would you be able to make a pull request? I don't think I'll have time, but could review it.

Copy link

@geekley geekley Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never done pull requests before... But I'll try to do it later.

Copy link
Contributor Author

@EvanHahn EvanHahn Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to email me at me@evanhahn.com if I can help!

@EvanHahn EvanHahn deleted the connect-nextFunction branch Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Popular package Unmerged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants