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

Express middleware for submounting Hono app #934

Open
sor4chi opened this issue Jan 14, 2025 · 9 comments
Open

Express middleware for submounting Hono app #934

sor4chi opened this issue Jan 14, 2025 · 9 comments
Labels
enhancement New feature or request

Comments

@sor4chi
Copy link
Contributor

sor4chi commented Jan 14, 2025

Which middleware is the feature for?

@hono/express

What is the feature you are proposing?

As I presented at Hono Conf 2024, if we can mount Hono as a sub-application of Express, it would enable a gradual migration from Express to Hono, which could increase the motivation to use Hono.

As a precedent, there is a framework with a similar motivation called @fastify/express.

I already have a POC implementation in hand, but I wanted to raise an issue for discussion. How do you think?

@sor4chi sor4chi added the enhancement New feature or request label Jan 14, 2025
@sor4chi
Copy link
Contributor Author

sor4chi commented Jan 14, 2025

@yusukebe
Copy link
Member

@sor4chi Thanks!

Related to #928 by @EdamAme-x

@sor4chi
Copy link
Contributor Author

sor4chi commented Jan 15, 2025

Wow, we already had a proposal!
I didn't notice because there was no issue, sorry.

@yusukebe
Copy link
Member

@sor4chi No problem!

Let's discuss it on #928.

@sor4chi
Copy link
Contributor Author

sor4chi commented Jan 15, 2025

BTW, the code that @EdamAme-x is suggesting is Express on Hono, but what I want to propose here is Hono on Express.

In reality, it would be quite challenging for an organization that uses Express to suddenly replace it with Hono, so I would like to propose a bottom-up migration approach.

@EdamAme-x
Copy link
Contributor

EdamAme-x commented Jan 15, 2025

I thought so too.
Can't this package (@hono/connect and @hono/express) be combined into one?

In Hono

app.use(connect(helmet()))

In Express (Connect)

app.use(hono(secureHeaders()))

@sor4chi
Copy link
Contributor Author

sor4chi commented Jan 15, 2025

const app = express()
app.use('/hono', hono(new Hono().get('/', (c) => c.text('Hello Hono in Express!'))))

app.listen(3000, () => {
  console.log('Server is running on http://localhost:3000')
})

It seems difficult.
I am imagining the submount of this kind of Hono application.

@yusukebe
Copy link
Member

@sor4chi @EdamAme-x

Ah, super sorry! I misunderstood. It can be enabled by using the Node Adapter:

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

const hono = new Hono()
hono.get('/', (c) => c.text('Hello from Hono!'))

const app = express()
app.use('/hono', getRequestListener(hono.fetch))

app.listen(3000)

@sor4chi
Copy link
Contributor Author

sor4chi commented Jan 15, 2025

Yes, that's true, but when considering usage in an actual environment, I think it will be necessary to pass things like loggers and DB connections, which can usually be included in the context, from Express to Hono.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants