Skip to content

Issue when setting base in vite.config.ts #131

@StephenPCG

Description

@StephenPCG

My case is similar to #72 , but I guest there are a little different.

I only configured base in vite.config.ts to /v2/, but didn't configure basename in react-router.config.ts. Because I would like to deploy my v2 webapp parallel to v1, using nginx to route page urls (for example, both v1 and v2 webapp provides '/', in engine, we route '/' to v2 webapp, so we can gradually deprecate v1). But the static files route can not be simply configured in nginx, so I have to change base of v2 webapp.

With this setup, the webapp fails in dev env. For example, the browser will request http://localhost:3000/v2/app/root.tsx, it seems that hono server doesn't handle this request itself, this is passed to react-router, and react-router treat this as a page request rather than static file request, and try to find a route match this url, and finally returns 404 (it actually renders routes/$.tsx, so I believe this is handled by react-router).

I tried to patch react-router-hono-server/node code, add rewriteRequestPath: (path) => path.replace(/^\/v2/, '') to app.use('*'), with no luck. I don't know how serveStatic() works in dev mode (vite does not write static files to disk in dev mode), so I can hardly dig deeper.

In production mode, there is no problem, I added this in createHonoServer():

export default await ({
 configure: (app) => {
    if (env.NODE_ENV === 'production') {
      app.use(
        '/v2/*',
        serveStatic({
          root: 'build/client',
          rewriteRequestPath: (path) => path.replace(/^\/v2/, ''),
        }),
      )
    }
 }
})

I have tried to remove the if to let it work in dev mode, with no luck.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions