-
-
Notifications
You must be signed in to change notification settings - Fork 7
Allow use of dynamic ports? #12
Comments
Ok, that's a nice feature that I completely forgot about. TLDR; Update to 0.0.0-experimental.52 I was going to provide the reply with something like "leaving it to dev to handle numeric string" but figured out that it required code more than 1 line, and realized that framework should handle that kind of stuff, which looks something like this: let port = +process.env.PORT
if(Number.isNan(port)) port = 3000
new KingWorld().listen(port) So the fix is released on exp.52 (see change here: #7680bdf, it should now accept stringified numeric value, so you can pass from Also, I believe I didn't write this down on documentation yet, but to access the port you can either:
So basically: const app = new KingWorld()
// listen can accept 2nd parameter callback for accessing `Bun.serve`
.listen(process.env.PORT ?? 8080, ({ hostname, port }) => {
console.log(
`🦊 KingWorld running at http://${hostname}:${port}`
)
})
// Or access it via `.server`, both are the same, as `.listen` is sync.
console.log(
`🦊 KingWorld running at http://${app.server?.hostname}:${app.server?.port}`
) Also, I believe I saw your profile picture on Bun Discord, if so feel free to tag me there if you find any issues. Let me know if you need anything, or else if you find this helpful, you can close the issue. |
Perfect, that fixes being able to pass in Still have 2 issues in regards to ports though.
|
Looks like the port 0 issue is related to bun itself not this lib oven-sh/bun#1544. |
I was hoping something like this could be added?
This would also help in this case.
The text was updated successfully, but these errors were encountered: