baojs icon indicating copy to clipboard operation
baojs copied to clipboard

app.listen() callback?

Open eladcandroid opened this issue 2 years ago • 5 comments

Do we have such a thing?

eladcandroid avatar Jul 10 '22 14:07 eladcandroid

I've seen this thing before. I would like to contribute.

fdemir avatar Jul 10 '22 22:07 fdemir

Do we have such a thing?

I'm unsure if this is needed, once app.listen() is executed, it will return a Server object and the code below it will continue to execute, e.g.

const server = app.listen();
console.log(server.hostname); // http://0.0.0.0:3000/

I might be wrong though - let me know if I've missed something!

mattreid1 avatar Jul 12 '22 18:07 mattreid1

Adding a callback like feature would be easy as this:

class Bao {
  listen(options: IListen = {}, cb?: () => void): Server {
    const server = Bun.serve(this.#serve(options));
  
    cb?.()
  
    return server
  }
}

wobsoriano avatar Jul 14 '22 23:07 wobsoriano

Adding a callback like feature would be easy as this:


class Bao {

  listen(options: IListen = {}, cb?: () => void): Server {

    const server = Bun.serve(this.#serve(options));

  

    cb?.()

  

    return server

  }

}

we can merge my pr actually for this.

fdemir avatar Jul 14 '22 23:07 fdemir

@fdemir Oh I did not notice 😅 awesome!

wobsoriano avatar Jul 14 '22 23:07 wobsoriano