Skip to content

added host option to plugin config, fixed devServer value in nette.json #2

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

jeremy-step
Copy link

@jeremy-step jeremy-step commented Jun 24, 2025

This PR adds a new host option to the plugin configuration. This allows to override the vite host config when needed.
Additionally, if the host value is set to true or '0.0.0.0', it is replaced with 'localhost', fixing incorrect urls in the generated nette.json file.

While http://0.0.0.0:5173 does work, it redirects to http://localhost:5173 for each asset loaded.

For example:

export default defineConfig({
	plugins: [nette({ host: 'custom-host.local' })],
	server: {
		host: true,
	},
});

will result in:

{ devServer: 'http://custom-host.local:5173' }

@jeremy-step
Copy link
Author

I probably should have included a test to make sure the plugin option overrides the vite host config. Will add it later today.

@jeremy-step
Copy link
Author

Should be ready to go.

@jeremy-step
Copy link
Author

jeremy-step commented Jun 26, 2025

When I was writing the Docker Dev section in the docs, I noticed that there is a bug with the host also being set to true in the autogenerated CORS config. Will fix it later today.

Edit: Done, also added auto configuration of the allowedHosts option, needed for Vite to work properly.

@MaN8fy
Copy link

MaN8fy commented Jul 10, 2025

Hi, thank you for your work. This works great for fixing the host issue.

However I ran into a case where I’d need the generated dev server URL to omit the port (i.e. just vite.localhost instead of vite.localhost:5173).

Would you consider adding a port option to the config (e.g. port: false, port: 80, port: 5173, etc.) to support that?

Could be helpful for setups with reverse proxies.

Thanks!

@jeremy-step
Copy link
Author

Hi, yeah, should be an easy fix. Will look into it later when I have a bit more time. In the meantime you could add a patch to the vite plugin yourself. There is a npm package (patch-package) for these situations that allows you to modify a package until whatever feature you need is released.

@jeremy-step
Copy link
Author

Should work now. The generated devServer url with the following example config would be http://vite.localhost.
While the plugin does a lot of the work for you when it comes to configuring CORS and Allowed Hosts, it doesn't account for a lot of cases that might need more complex configuration. Depending on your needs, you might need to configure that stuff yourself.

export default defineConfig({
    plugins: [
        nette({
            host: "vite.localhost",
        }),
    ],
    server: {
        host: true, // Or '0.0.0.0'
        port: 80,
        strictPort: true,
    },
    ...
});

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.

2 participants