Skip to content

feat: introduce serve command#6

Merged
yusukebe merged 14 commits into
mainfrom
feat/serve
Oct 15, 2025
Merged

feat: introduce serve command#6
yusukebe merged 14 commits into
mainfrom
feat/serve

Conversation

@yusukebe

@yusukebe yusukebe commented Oct 9, 2025

Copy link
Copy Markdown
Member

No description provided.

Co-authored-by: Taku Amano <taku@taaas.jp>
@usualoma

Copy link
Copy Markdown
Member

default port

I 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.

IMG_0722

I considered 🔥 's Unicode as well, but nothing really worked out.

If there's nothing good, I think 3000 yen is perfectly fine.

@yusukebe

Copy link
Copy Markdown
Member Author

@usualoma

Nice suggestion! I love 7070! Lucky numbers!

I found it is a registered port number, but WHAT IS ARCP?

CleanShot 2025-10-13 at 15 48 28@2x

https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=7070

My ChatGPT said this is a short name of Audio/Video Resource Control Protocol by RealNetworks, Inc.?? RealNetworks? Was it used RealPlayer??

Anyway, we may use 7070 because it is not active. Another case, Wrangler by Cloudflare uses the 8787 port as the default. This port is already registered by msgsrvr.

https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=8787

@usualoma

Copy link
Copy Markdown
Member

Alright, let's go with 7070!

@yusukebe
yusukebe marked this pull request as ready for review October 14, 2025 22:03
@yusukebe

Copy link
Copy Markdown
Member Author

Hi @usualoma !

What do you think of the current implementation, especially the functional aspect?

@usualoma usualoma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
           })

Comment thread src/commands/serve/builtin-map.ts Outdated
getRuntimeKey: 'hono/adapter',

// Helpers - Connection Info
getConnInfo: 'hono/conninfo',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like serveStatic, I think we should import @hono/node-server/conninfo.

Suggested change
getConnInfo: 'hono/conninfo',
getConnInfo: '@hono/node-server/conninfo',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' } }

@yusukebe
yusukebe requested a review from usualoma October 15, 2025 07:30
@yusukebe

Copy link
Copy Markdown
Member Author

Thanks @usualoma ! Can you review this again?

@usualoma usualoma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe

Copy link
Copy Markdown
Member Author

@usualoma Thanks!

@yusukebe
yusukebe merged commit 12df223 into main Oct 15, 2025
3 checks passed
@yusukebe
yusukebe deleted the feat/serve branch October 15, 2025 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants