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

Support SPA like express #3124

Closed
ckken opened this issue Jul 10, 2024 · 9 comments
Closed

Support SPA like express #3124

ckken opened this issue Jul 10, 2024 · 9 comments
Labels
enhancement New feature or request.

Comments

@ckken
Copy link

ckken commented Jul 10, 2024

What is the feature you are proposing?

app.use(express.static(staticRoot))//dist
app.get('*', (req, res) => res.send(html))//html in dist

@ckken ckken added the enhancement New feature or request. label Jul 10, 2024
@EdamAme-x
Copy link
Contributor

Hi @ckken
hmm....

I think it was already implemented in Hono.

app.use(serveStatic({ root: staticPath }) }) // dist
app.get('*', (c) => c.html(html)) // html in dist

@ckken
Copy link
Author

ckken commented Jul 11, 2024

we use hono replace express in webpack cli,Absolute root path must be use in express.static

@EdamAme-x
Copy link
Contributor

EdamAme-x commented Jul 11, 2024

hmm...
I think it's unnecessary.
You can use a relative path.

app.use(serveStatic({ root: "./dist" }) }) // dist
app.get('*', (c) => c.html(html)) // html in dist

If we don't think the problem of performance, you can use .mount()

@ckken
Copy link
Author

ckken commented Jul 11, 2024

The cli does not exist in the project, but is installed through npm, while hono is integrated into the cli, so there are similar demos

@EdamAme-x
Copy link
Contributor

I may be mistaken.
Do you want to migrate express to hono?
Do you want to migrate hono to express?
Or another? @ckken

@ckken
Copy link
Author

ckken commented Jul 11, 2024

like this #3107

@EdamAme-x
Copy link
Contributor

hmm...
I'm not quite sure what the intent is. sorry

please explain the details?

@ckken
Copy link
Author

ckken commented Jul 11, 2024

fixed it!

import {serveStatic} from 'hono/serve-static'
app.use(
      '*',
      serveStatic({
        root: '/',
        pathResolve(filePath: string) {
          return path.resolve(store.outDir, filePath)
        },
        getContent(filePath, c) {
          return fsp.readFile(filePath)
        },
      }),
    )

@ckken ckken closed this as completed Jul 11, 2024
@EdamAme-x
Copy link
Contributor

Good, I'm relieved.

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

2 participants