feat: introduce serve command#6
Conversation
Co-authored-by: Taku Amano <taku@taaas.jp>
default portI think it would be great if Hono could use its own port number, like how Vite uses 5173. However, I've been thinking about it, but I can't come up with any good numbers that aren't already registered with IANA. I considered 🔥 's Unicode as well, but nothing really worked out. If there's nothing good, I think 3000 yen is perfectly fine. |
|
Nice suggestion! I love I found it is a registered port number, but WHAT IS ARCP?
My ChatGPT said this is a short name of Anyway, we may use |
|
Alright, let's go with |
|
Hi @usualoma ! What do you think of the current implementation, especially the functional aspect? |
usualoma
left a comment
There was a problem hiding this comment.
new Function('c', 'next', ...functionNames,
return (${use}))
I see, that's a clever approach!
I thought it might be better to do the new Function outside the handler.
diff --git i/src/commands/serve/index.ts w/src/commands/serve/index.ts
index 286ccdb..2cf37b7 100644
--- i/src/commands/serve/index.ts
+++ w/src/commands/serve/index.ts
@@ -75,12 +75,12 @@ export function serveCommand(program: Command) {
const baseApp = new Hono()
// Apply middleware from --use options
for (const use of options.use || []) {
- baseApp.use(async (c, next) => {
- // Create function with all available functions in scope
- const functionNames = Object.keys(allFunctions)
- const functionValues = Object.values(allFunctions)
+ // Create function with all available functions in scope
+ const functionNames = Object.keys(allFunctions)
+ const functionValues = Object.values(allFunctions)
- const func = new Function('c', 'next', ...functionNames, `return (${use})`)
+ const func = new Function('c', 'next', ...functionNames, `return (${use})`)
+ baseApp.use(async (c, next) => {
const middleware = func(c, next, ...functionValues)
return typeof middleware === 'function' ? middleware(c, next) : middleware
})| getRuntimeKey: 'hono/adapter', | ||
|
|
||
| // Helpers - Connection Info | ||
| getConnInfo: 'hono/conninfo', |
There was a problem hiding this comment.
Just like serveStatic, I think we should import @hono/node-server/conninfo.
| getConnInfo: 'hono/conninfo', | |
| getConnInfo: '@hono/node-server/conninfo', |
There was a problem hiding this comment.
Thanks! Fixed: 3a02408 This works.
$ hono serve --use "(c) => console.log(getConnInfo(c))"
Listening on http://localhost:7070
{ remote: { address: '::1', port: 63573, addressType: 'IPv6' } }
|
Thanks @usualoma ! Can you review this again? |
|
@usualoma Thanks! |


No description provided.