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

[9.x] Added support for custom proxy urls #43273

Closed
wants to merge 1 commit into from

Conversation

gsguglielmo
Copy link

Implementation of this feature #43262

This pull request adds the option to manually specify the base url of the vite development server, so it can be used behind a reverse proxy.
If the config option app.vite_hot_proxy_url is present, all tags generated with the @vite directive, will have the specified value as it's base URL.
Mix has a similar feature with app.mix_hot_proxy_url.

Added the support for the `app.vite_hot_proxy_url` config. This config will be used for the base url of the tag generated with the `@vite` directive
@gsguglielmo gsguglielmo changed the title Added support for custom proxy urls [9.x] Added support for custom proxy urls Jul 19, 2022
@taylorotwell
Copy link
Member

Will let @jessarcher review this - @jessarcher please mark as ready for review when you're ready for me to take a look

@taylorotwell taylorotwell marked this pull request as draft July 19, 2022 13:52
@jessarcher
Copy link
Member

jessarcher commented Jul 20, 2022

Hi @gsguglielmo, thanks for the PR.

I think before we look at adding this customisation, it would be good to see if we can get your custom host into the hot file itself.

Vite allows you to configure where its client should look for the HMR server, and the Laravel Vite plugin also respects this since v0.3.

Try adding the following to your Vite config:

export default defineConfig({
  // ...
  server: {
    hmr: {
      // protocol: 'wss', // Only if you need a https URL and the Vite server is not running on HTTPS
      host: 'your-custom-host',
    },
  },
});

If you need to customise the port, you may specify the VITE_PORT environment variable.

@gsguglielmo
Copy link
Author

The host part does seem to solve part of the issue, the hostname part od the hot file is ok, but the port is not.

I've tried the VITE_PORT environment variable but does not seem to have an effect on the tag that is being rendered by the blade directive.
image
I've tried to use the server.port and server.hmr.port but in both cases vite will try to bind the server to that port which if the dev server port and the final forwarded port don't match, it won't work.

If you set server.hmr.port in the config Vite will also resolve the FQDN and will try to bind the server to that address too, in my case the server is running inside a docker container, so the ip associated to the FQDN doesn't match any ip that the sev server can bind to.
image

For the port part of the hot file it will always be the port of the http server:
https://github.com/laravel/vite-plugin/blob/a766dd50825037b7914b66b1f0b6f29199a219ff/src/index.ts#L152-L158
https://github.com/laravel/vite-plugin/blob/a766dd50825037b7914b66b1f0b6f29199a219ff/src/index.ts#L340-L351

@jessarcher
Copy link
Member

jessarcher commented Jul 22, 2022

Hi @gsguglielmo, I'd be open to updating laravel-vite-plugin to respect server.hmr.clientPort if configured by the user.

There is already a PR at laravel/vite-plugin#63 that I will look at merging.

@timacdonald
Copy link
Member

@gsguglielmo because the PR @jessarcher mentioned has been merged, does that solve your issue and should we close this one?

@jessarcher
Copy link
Member

Going to close this as laravel/vite-plugin#63 is merged and should hopefully address the issue.

@jessarcher jessarcher closed this Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants