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

feat: Stabilize Deno.serve() API #19141

Merged
merged 14 commits into from
Jul 3, 2023

Conversation

bartlomieju
Copy link
Member

No description provided.

@bartlomieju bartlomieju added this to the 1.34 milestone May 16, 2023
@lino-levan
Copy link
Contributor

The actual PR LGTM.

One thing I am concerned about is the type signature of the method. I don't recall another API in which the options argument is first. iirc there was a PR to remove this option, but perhaps serve(handler, options) would make more sense? Just trying to get some clarity on this decision, don't really have a strong opinion either way.

@bartlomieju
Copy link
Member Author

The actual PR LGTM.

One thing I am concerned about is the type signature of the method. I don't recall another API in which the options argument is first. iirc there was a PR to remove this option, but perhaps serve(handler, options) would make more sense? Just trying to get some clarity on this decision, don't really have a strong opinion either way.

IIRC no other Deno API accepts a callback, in case of Deno.serve() lots of people define handler inline, which often spans multiple lines. In such case it's very easy to miss that after the handler there's also an options bag.

@lino-levan
Copy link
Contributor

In such case it's very easy to miss that after the handler there's also an options bag.

That reasoning makes sense to me, thanks for clarifying!

@lucacasonato
Copy link
Member

Also, there is precedent for options bag first: Deno.test.

@bartlomieju
Copy link
Member Author

Also, there is precedent for options bag first: Deno.test.

Doh, of course Deno.test and Deno.bench take callbacks 😅

@bartlomieju bartlomieju removed this from the 1.34 milestone May 19, 2023
@bartlomieju
Copy link
Member Author

I have to postpone this PR due to #19189.

@bartlomieju bartlomieju added this to the 1.35 milestone May 21, 2023
@mmastrac
Copy link
Contributor

@lucacasonato pointed out some documentation issues -- I compared the current version of the HTTP server docs with what will be required. For the most part we should be able to swap out serveHttp for serve, but there are some additional documentation items that will have to change

#19306

@mmastrac mmastrac mentioned this pull request May 29, 2023
7 tasks
cli/tsc/dts/lib.deno.ns.d.ts Outdated Show resolved Hide resolved
@kt3k
Copy link
Member

kt3k commented Jun 30, 2023

A few questions:

  • Is port 9000 sensible default? (Currently std's serve defaults to 8000. If Deno.serve is the successor of it, maybe we should keep 8000 as default?)
  • Is the 3rd overload really necessary? (The difference of the 2nd and the 3rd looks marginal)

@bartlomieju
Copy link
Member Author

A few questions:

  • Is port 9000 sensible default? (Currently std's serve defaults to 8000. If Deno.serve is the successor of it, maybe we should keep 8000 as default?)

Sure, we can change it to be 8000.

  • Is the 3rd overload really necessary? (The difference of the 2nd and the 3rd looks marginal)

We discussed overloads two months ago and already removed some of them. @lucacasonato was rather adamant on keeping these 3.

unref(): void;
}

/** Serves HTTP requests with the given handler.
Copy link
Member

Choose a reason for hiding this comment

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

these docs are repeated for each overload?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's a requirement for deno_doc

Copy link
Member

Choose a reason for hiding this comment

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

Maybe each doc should be specific to the overload? Or maybe we should just consider that a bug in deno_doc and do what makes sense in the d.ts file. It does not make sense to duplicate documentation three times - so there's definitely a bug here (either in deno_doc or jsdoc spec)

Copy link
Member Author

Choose a reason for hiding this comment

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

CC @dsherret @crowlKats do you remember the reason why this was needed? Can we somehow flatten all three overloads to be next to each other with only a single doc?

Copy link
Member

Choose a reason for hiding this comment

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

a doc block is specific to its overload; there is no way to specify a single doc for all overloads. unsure how we could change this, as it is favourable to have the capability to document overloads differently from each other.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the docs so that each overload has a different doc string.

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

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

LGTM. Great work to everyone involved!

Let's make sure to update the manual after this lands.

@bartlomieju bartlomieju merged commit 3c8bbc4 into denoland:main Jul 3, 2023
11 checks passed
@bartlomieju bartlomieju deleted the stabilize_deno_serve branch July 3, 2023 23:51
@0f-0b
Copy link
Contributor

0f-0b commented Jul 4, 2023

serve is still listed in denoNsUnstable and is not present at runtime without --unstable.

serve: http.serve,

$ deno --version
deno 1.34.3+686ec85 (canary, x86_64-apple-darwin)
v8 11.6.189.7
typescript 5.1.6
$ deno eval 'console.log(Deno.serve)'
undefined
$ deno eval --unstable 'console.log(Deno.serve)'
[Function: serve]

@bartlomieju
Copy link
Member Author

Wow, thanks for pointing this out @0f-0b, fix incoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants