vite icon indicating copy to clipboard operation
vite copied to clipboard

Start on multiple hosts

Open boindil opened this issue 1 year ago • 7 comments

Description

It seems as if it is not possible to start using multiple IPs/hosts. I've tried separating by comma, but thats throwing an error. As of now it seems that it's only possible to use one host or all ...

Suggested solution

add support for multiple hosts (perferrably as array: host: string | boolean | array).

Alternative

No response

Additional context

No response

Validations

boindil avatar Apr 04 '24 08:04 boindil

Can you explain why you want to start on multiple host? Node.js createServer only supports starting on one host (unless DNS could resolve multiple different hosts to this one).

bluwy avatar Apr 09 '24 08:04 bluwy

Can you explain why you want to start on multiple host? Node.js createServer only supports starting on one host (unless DNS could resolve multiple different hosts to this one).

multiple sub-domain, eg laravel route support multiple domain and php artisan serve not support ssl, so just can use vite/apache to run ssl to dev

tszyuloveyou avatar May 07 '24 02:05 tszyuloveyou

I suppose we can call .listen() multiple times to support multiple hosts, but it doesn't seem like a common usecase. There's the same discussion in webpack: https://github.com/webpack/webpack-dev-server/issues/400

bluwy avatar May 08 '24 03:05 bluwy

I am currently facing the same issue. The app will run on multiple subdomains in production and I need to replicate this for development.

KevsRepos avatar May 24 '24 11:05 KevsRepos

facing the same issue. I would like to run an instance for each of the environments: mock data environment, dev environment and production environment simultaneously Each environment is using HTTPS protocol and runs on port 443 with different host names

noyoliel-devocean avatar Jun 24 '24 19:06 noyoliel-devocean

I have a use case for this as well (originally reported in https://github.com/vitejs/vite/issues/18469)

TLDR: I want vite to run on IPv4 (127.0.0.1) and IPv6 (::1) simultaneously to make it easier for us to use a custom domain for local development (e.g. local.example.com points to either 127.0.0.1 or ::1, but we don't know if the developer uses IPv4 or IPv6 on their machine, local.example.com can use IPv4 while localhost uses IPv6, leading to a mismatch)

My workaround ended up being this, so it's still just listening on a single host, but we're smarter about how to pick it:

const { family } = await dns.promises.lookup("local.example.com");

export default defineConfig({
	plugins: [tsconfigPaths(), react()],
	server: {
		port: 3000,
		host: family === 6 ? "::1" : "127.0.0.1",
	},
});

MarcusCaspeco avatar Oct 25 '24 15:10 MarcusCaspeco