Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app.mount() is not working with @hono/node-server #147

Closed
yusukebe opened this issue Feb 18, 2024 · 6 comments · Fixed by #148
Closed

app.mount() is not working with @hono/node-server #147

yusukebe opened this issue Feb 18, 2024 · 6 comments · Fixed by #148

Comments

@yusukebe
Copy link
Member

This code does not work well:

import { serve } from '@hono/node-server'
import { Hono } from 'hono'

const app = new Hono()

app.mount('/mount', () => {
  return new Response('foo')
})

serve(app)

The error message:

TypeError: Cannot read properties of undefined (reading 'keepalive')
    at get keepalive [as keepalive] (node:internal/deps/undici/undici:5612:29)
    at Object.RequestInit (node:internal/deps/undici/undici:1779:33)
    at new Request (node:internal/deps/undici/undici:5253:34)
    at Request (/Users/yusuke/work/node/my-app-node/node_modules/@hono/node-server/dist/index.js:55:5)
    at Array.handler (/Users/yusuke/work/node/my-app-node/node_modules/hono/dist/cjs/hono-base.js:191:9)
    at Hono.dispatch (/Users/yusuke/work/node/my-app-node/node_modules/hono/dist/cjs/hono-base.js:235:37)
    at fetch (/Users/yusuke/work/node/my-app-node/node_modules/hono/dist/cjs/hono-base.js:82:19)
    at Server.<anonymous> (/Users/yusuke/work/node/my-app-node/node_modules/@hono/node-server/dist/index.js:399:13)
    at Server.emit (node:events:514:28)
    at Server.emit (node:domain:488:12)
@yusukebe
Copy link
Member Author

Hi @usualoma

Can you see this issue? I think this is a definite bug and should be fixed.

@usualoma
Copy link
Member

Hi @yusukebe

I think the following PR can fix this issue.
#148

@ManuelFernando
Copy link

@yusukebe I had same problem because using app.mount() I can't access to any headers. These are protected, is there a way to read the request. For example when I use req.headers['content-type'] -> this return undefined

@yusukebe
Copy link
Member Author

yusukebe commented Sep 2, 2024

Hi @ManuelFernando

I can't reproduce it. Please provide a minimal project to reproduce it.

@ManuelFernando
Copy link

ManuelFernando commented Sep 2, 2024

Hi @ManuelFernando

I can't reproduce it. Please provide a minimal project to reproduce it.

@yusukebe, when it's used console.log(req.headers) in the console appears string representation but any of their field can be accessed

import { serve } from '@hono/node-server';
import { Hono } from 'hono';

const app = new Hono();

app.mount('/status', (req) => {
  console.log(req.headers.accept); // -> return undefined
  console.log(req.headers['content-type']) // -> return undefined
  console.log(Object.keys(req.headers)) // -> return []
});

app.get('/', (c) => {
  return c.html(
    <html>
      <body>
        <form method="POST" action="/status">
          <button type="submit">submit</button>
        </form>
      </body>
    </html>
  )
})

const port = 3002;
console.log(`Server is running on port ${port}`);

serve({
  fetch: app.fetch,
  port,
  overrideGlobalObjects: false
});

@yusukebe
Copy link
Member Author

yusukebe commented Sep 2, 2024

@ManuelFernando

The req.headers is a Headers object.

Try:

req.headers.get('Accept')

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 a pull request may close this issue.

3 participants