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

Allow disabling spa middleware #5720

Closed
4 tasks done
Artur- opened this issue Nov 17, 2021 · 5 comments
Closed
4 tasks done

Allow disabling spa middleware #5720

Artur- opened this issue Nov 17, 2021 · 5 comments

Comments

@Artur-
Copy link
Contributor

Artur- commented Nov 17, 2021

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

@Artur-
Copy link
Contributor Author

Artur- commented Nov 17, 2021

I'd be happy to create a PR for this but I will wait for some input first, like how the configuration should be done

@Niputi
Copy link
Contributor

Niputi commented Nov 17, 2021

reference about disabling middlewares #4640

@Artur-
Copy link
Contributor Author

Artur- commented Nov 17, 2021

I can only think of one solution which makes sense and that would be a ServerOption like

    /**
     * When `true`, the index page is sent as the response to all requests 
     * which do not refer to a resource.
     */
    spa?: boolean

Or if it is desirable that the default value is false, disableSpa

All other solutions I can think of imply

  • the middleware names become public API
  • the user must understand what each middleware does
  • the API is based on internal details and not on functionality

All which sound quite undesirable

@brillout
Copy link
Contributor

brillout commented May 9, 2022

See #8061.

@benmccann
Copy link
Collaborator

Implemented in #8217

@github-actions github-actions bot locked and limited conversation to collaborators Jun 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants