cloudflare / cloudflare/workerd
Support class exports or clarify error message
- Dominant language
- C++
- Stars
- 8.7k
- Forks
- 739
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 174
Description
One nice pattern I've used for Durable Objects is to implement the eyeball fetch as a static method on the object's class, ie:
```js
class Host {
static fetch(request, env) {
let {hostname} = new URL(request.url)
let hostId = env.hosts.idFromName(hostname)
return env.hosts.get(hostId).fetch(request)
}
fetch(request) {
return new Response('ok')
}
}
```
Currently I can use this pattern like this:
```js
export {Host}
export default {fetch: Host.fetch}
```
but ideally I'd be able to export the class itself, since it meets the requirements of being an object with a `fetch` property:
```js
export {Host, Host as default}
```
`workerd serve` accepts this, but then fails at runtime with the following error:
```
workerd/io/worker-entrypoint.c++:210: error: e = kj/async-io-unix.c++:1651: failed: connect() blocked by restrictPeers()
```
I feel like `workerd` should either support this kind of export, or fail at compile time with a clearer error.
Contributor guide
Assessment
This issue has not been assessed yet.