Skip to content

Allow disabling spa middleware #5720

@Artur-

Description

@Artur-

Clear and concise description of the problem

We are running Vite from Java and to talk to the dev server, we use its http server. We are kind of wanting to run it in middleware mode but cannot use middleware mode directly. In this case, the viteSpaFallbackMiddleware is undesireable as the actual SPA part of the application is handled through a Java server and we want to load frontend resources from Vite. Having the spa middleware enable makes it impossible to know if a certain URL refers to a frontend resource or not, as all URLs that do not refer to resources will still return 200 and the index.html contents.

Suggested solution

Add an option to disable viteSpaFallbackMiddleware even when the middleware option is off.

Alternative

We are currently removing the middleware by force using something like

              context.server.middlewares.stack = context.server.middlewares.stack.filter((mw) => {
                const handleName = '' + mw.handle;
                return !handleName.includes('viteSpaFallbackMiddleware');
              });

It is not pretty

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions