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 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" }.
@EvanHahn EvanHahn mentioned this pull request Apr 10, 2018
4 of 4 tasks complete
@@ -17,9 +18,11 @@ declare function createServer(): createServer.Server;
declare namespace createServer {
export type ServerHandle = HandleFunction | http.Server;

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

This comment has been minimized.

Copy link
@mohsen1

mohsen1 Apr 10, 2018

Contributor

isn't error null | Error?

This comment has been minimized.

Copy link
@EvanHahn

EvanHahn Apr 10, 2018

Author Contributor

All of these are valid in Connect:

next();
next(null);
next(new Error("Something bad happened!"));
next(404);
next(true);
@typescript-bot

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

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
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@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;

This comment has been minimized.

Copy link
@geekley

geekley Nov 12, 2019

@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

This comment has been minimized.

Copy link
@EvanHahn

EvanHahn Nov 12, 2019

Author Contributor

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.

This comment has been minimized.

Copy link
@geekley

geekley Nov 12, 2019

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

This comment has been minimized.

Copy link
@EvanHahn

EvanHahn Nov 12, 2019

Author Contributor

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

@EvanHahn EvanHahn deleted the EvanHahn:connect-nextFunction branch Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.