Skip to content

Commit

Permalink
fix: port (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
HomyeeKing committed Nov 5, 2021
1 parent 0c31c47 commit 0acff16
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,14 @@ function PluginInspect(options: Options = {}): Plugin {
}
})

if (server.httpServer?.listen) {
// hijack httpServer.listen to print the log
const _listen = server.httpServer.listen
let port = config.server.port || 3000
const protocol = config.server.https ? 'https' : 'http'
let timer: any
server.httpServer.listen = function(this: any, ...args: any) {
port ||= args[0]
clearTimeout(timer)
timer = setTimeout(() => {
// eslint-disable-next-line no-console
console.log(` > Inspect: ${yellow(`${protocol}://localhost:${port}/__inspect/`)}\n`)
}, 0)
return _listen.apply(this, args)
}
}
server.httpServer?.once('listening',()=>{
const protocol = config.server.https ? 'https' : 'http'
const port = config.server.port
setTimeout(() => {
// eslint-disable-next-line no-console
console.log(` > Inspect: ${yellow(`${protocol}://localhost:${port}/__inspect/`)}\n`)
}, 0);
})
}

return <Plugin>{
Expand Down

0 comments on commit 0acff16

Please sign in to comment.