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

Unable to setup fallback when using parent directory in path #3242

Closed
staniboy opened this issue Aug 7, 2024 · 5 comments
Closed

Unable to setup fallback when using parent directory in path #3242

staniboy opened this issue Aug 7, 2024 · 5 comments

Comments

@staniboy
Copy link

staniboy commented Aug 7, 2024

What version of Hono are you using?

4.5.4

What runtime/platform is your app running on?

Bun

What steps can reproduce the bug?

import { Hono } from "hono";
import { expensesRoute } from "./routes/expenses";
import { serveStatic } from "hono/bun";

const app = new Hono();

app.route("/api/expenses", expensesRoute);

app.get("*", serveStatic({ root: "../client/dist" }));
app.get("*", serveStatic({ path: "../client/dist/index.html" })); // fallback

export default app;

This will serve the root from client/dist and display index.html but will fail to trigger fallback to index.html when non existing path is specified.

I've then moved my client build inside of server project folder and used:

app.get("*", serveStatic({ root: "./public" }));
app.get("*", serveStatic({ path: "./public/index.html" })); // fallback

in this case fallback worked properly.

What is the expected behavior?

Fallback path with parent directory working

What do you see instead?

Fallback path with parent directory not working

Additional information

No response

@staniboy staniboy added the triage label Aug 7, 2024
@rjoydip
Copy link

rjoydip commented Aug 8, 2024

@staniboy You can check #3108 (comment) and PR #3108, honojs/node-server#78

For workaround, you can do something like below

// for client
app.get("*", serveStatic({ root: `${relative(process.cwd(), __dirname)}/../client/dist/` }));
app.get("*", serveStatic({ path: `${relative(process.cwd(), __dirname)}/client/dist/index.html` })); // fallback 

// for public
app.get("*", serveStatic({ root: `${relative(process.cwd(), __dirname)}/public/` }));
app.get("*", serveStatic({ path: `${relative(process.cwd(), __dirname)}/public/index.html` })); // fallback

If you use ES modules then instead of using __dirname you can use import.meta.dirname

Duplicate #2200

@yusukebe yusukebe added not bug and removed triage labels Aug 8, 2024
@yusukebe
Copy link
Member

yusukebe commented Aug 8, 2024

Regarding this problem, it's not an actual bug, but we have to consider to solve it.

@yusukebe
Copy link
Member

Related to #3420

Copy link

github-actions bot commented Nov 4, 2024

This issue has been marked as stale due to inactivity.

@github-actions github-actions bot added the stale label Nov 4, 2024
Copy link

github-actions bot commented Nov 7, 2024

Closing this issue due to inactivity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants