-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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 Vite to serve from pages other than index.html #5547
Comments
As another reason why this would be useful, I think it would resolve an issue in mocha-vite-puppeteer: larsthorup/mocha-vite-puppeteer#28 (comment) |
Similar issue encountered, I'm working with multi-page apps and I suppose that vite could provide any option to disable the spa-fallback middleware to work with other express middlewares like serve-index |
You can do so using the |
I think using Something like (untested): import history from 'connect-history-api-fallback'
export function speciallSpaFallback() {
return {
name: 'special-spa-fallback',
config() {
return {
appType: 'mpa'
}
},
configureServer(server) {
return () => {
server.middlewares.use(history(/* custom config */))
}
}
}
} Let me know if this works for you |
Hey @steveworkman, did you get this working by any chance? Im looking for what i think is the exact same thing. |
Closing due to lack of response |
Clear and concise description of the problem
As a developer using Vite I want to be able to serve from different HTML pages so that I may more closely replicate my production environment.
I have an application that once built produces two different index.html pages for two different brands, for example
index-a.html
andindex-b.html
.The production web server then chooses which of these html files to serve in SPA mode based on the domain that the request is coming from, so www.example.com goes to
index-a.html
and www.test.com goes toindex-b.html
I'm trying to replicate this with the vite dev server, but I can't because the served page is hard-coded as index.html which you can see in the
spaFallback
middleware.I've attempted to override this using a plugin and middleware, but I either get into an infinite redirection loop, or the server never serves the request.
This is not the same as multi-page apps as the target here is SPAs and even with a multi-page app you still need an
index.html
file in the root of the project. It is also not the same as being able to change the directory that the page is served from - the issue is being able to serve from a file other thanindex.html
.Suggested solution
Add a configuration property:
server.indexFile
with a default ofindex.html
that is then used by thevite:spa-fallback
module to retrieve the right index file. This should also be able to be set from the command line in thevite serve
andvite preview
commands.This should not interfere with the multi-page app setup
Alternative
I've attempted to do this with a plugin, but I don't believe that I can effectively override the
vite:spa-fallback
middleware.Additional context
Previously asked in the Discussions area with no positive response.
Validations
The text was updated successfully, but these errors were encountered: