Skip to content

Commit

Permalink
Merge pull request #380 from paperdave-forks/dave/not-in-bun-error
Browse files Browse the repository at this point in the history
fix: display the correct error message when calling .listen outside of bun
  • Loading branch information
SaltyAom authored Jan 5, 2024
2 parents e97c605 + 34b6a0f commit ac1c8c9
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3984,7 +3984,10 @@ export default class Elysia<
options: string | number | Partial<Serve>,
callback?: ListenCallback
) => {
if (!Bun) throw new Error('Bun to run')
if (typeof Bun === 'undefined')
throw new Error(
'.listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch'
)

this.compile()

Expand Down Expand Up @@ -4024,11 +4027,6 @@ export default class Elysia<
error: this.outerErrorHandler
} as Serve)

if (typeof Bun === 'undefined')
throw new Error(
'.listen() is designed to run on Bun only. If you are running Elysia in other environment please use a dedicated plugin or export the handler via Elysia.fetch'
)

this.server = Bun?.serve(serve)

if (this.event.start.length)
Expand Down

0 comments on commit ac1c8c9

Please sign in to comment.