-
Notifications
You must be signed in to change notification settings - Fork 5.6k
feat(serve): support export default class #28751
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
base: main
Are you sure you want to change the base?
Conversation
167efe4
to
c593686
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it makes sense to support a class declaration here like:
export default class Foo implements Deno.ServeDefaultExport {
fetch(_request: Request) {
return new Response("Hello world!");
}
}
...because generally classes are used to inject stuff in the constructor then pass around the instances. So practically someone would probably do something like:
const someInstance = new Foo(...some args here...);
// then
export default someInstance;
...which seems to be all that's necessary for #24062 ?
@dsherret fair point, dropped that from the PR so that only class instances are supported. |
class Foo implements Deno.ServeDefaultExport { | ||
fetch(_request: Request) { | ||
return new Response("Hello world!"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe let's try updating this test to use something on the instance? For example, something like:
class Foo implements Deno.ServeDefaultExport {
message = "Hello world!";
fetch(_request: Request) {
return new Response(this.message);
}
}
I think right now it will not work because we need to bind the function to the instance.
This PR adds support for passing a class instance for
deno serve
export default fetch.Fixes #24062