Allow Vite to serve from pages other than index.html

See original GitHub issue

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 and index-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 to index-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 than index.html.

Suggested solution

Add a configuration property: server.indexFile with a default of index.html that is then used by the vite:spa-fallback module to retrieve the right index file. This should also be able to be set from the command line in the vite serve and vite 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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:23
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bluwycommented, Nov 9, 2022

Closing due to lack of response

0reactions
mr-motocommented, Oct 23, 2022

Hey @steveworkman, did you get this working by any chance? Im looking for what i think is the exact same thing. I have a plugin that takes the index.html and build out multiple different html files ( in my case different language files like en.html, fr.html etc ). Looking to be able to access localhost:3000/en.html and so on

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Options - Vite
clientPort is an advanced option that overrides the port only on the client side, allowing you to serve the websocket on a different...
Read more >
Building for Production - Vite
When it is time to deploy your app for production, simply run the vite build command. By default, it uses <root>/index.html as the...
Read more >
Configuring Vite
'ssr' will disable Vite's own HTML serving logic so that you should serve index.html manually. 'html' will enable Vite's own HTML serving logic....
Read more >
Deploying a Static Site - Vite
The vite preview command will boot up a local static web server that serves the files from dist at http://localhost:4173 . It's an...
Read more >
Build Options - Vite
The polyfill is auto injected into the proxy module of each index.html entry. ... This option allows users to set a different browser...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found