twozeroxic
twozeroxic

Reputation: 133

Blocked request. This host ("frontend_web") is not allowed

When building vite react in docker-compose application, a message appears when opening the web-site page Blocked request. This host ("frontend_web") is not allowed. To allow this host, add "frontend_web" to `server.allowedHosts` in vite.config.js.

I tried to use "vite-plugin-allowed-hosts" but it gives me an error when building the docker-container [ERROR] Failed to resolve entry for package "vite-plugin-allowed-hosts". The package may have incorrect main/module/exports specified in its package.json. [plugin externalize-deps]

Upvotes: 8

Views: 8009

Answers (2)

elMatador
elMatador

Reputation: 71

Since Vite 6.0.9+, 5.4.12+, 4.5.6+, you need to set preview.allowedHost if you are accessing the server with a host name other than localhost.

https://github.com/vitejs/vite/discussions/19426

Upvotes: 0

ansmonjol
ansmonjol

Reputation: 396

A recent Vite update (6.0.11, to my knowledge) has introduced changes that "break" setups using proxies. To resolve this, you need to configure allowedHosts in your Vite configuration as told.

In your case this should work:

server: {
  allowedHosts: ['frontend_web'],
}

Upvotes: 18

Related Questions