How to expose 'host' for external device display? #3396
-
Previously, when you run "npm run dev" it showed something like:
Now, there is no Network address but:
How do you get it to work? And why remove such a feature? |
Beta Was this translation helpful? Give feedback.
Replies: 18 comments 50 replies
-
The default host now listens to
Or set |
Beta Was this translation helpful? Give feedback.
-
I'd like to add here that you can use:
to run it on a one-off occasion without having to modify your config or command definition in package.json |
Beta Was this translation helpful? Give feedback.
-
I'm running multiple vite servers on 1 machine, where I want to bind vite to different local IPs, but always on the same port. Do avoid external access, I'm using Please have look on the Stackblitz example with 127.0.0.2 And also have look on the Stackblitz example with 127.0.0.1
EDIT: It's correctly binding, but it's printing like if the server is bound to every network adapter... |
Beta Was this translation helpful? Give feedback.
-
Hi i want to ask can i access this in a different device? when i tried to do |
Beta Was this translation helpful? Give feedback.
-
Is there any way I can "replicate" the session for a host ? I want whoever that externally access the server to have the same "view", the same session as the localhost |
Beta Was this translation helpful? Give feedback.
-
cool
…On Mon, Nov 28, 2022 at 8:15 AM VelkanAlpha ***@***.***> wrote:
*Perfect*
—
Reply to this email directly, view it on GitHub
<#3396 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGK5N5GCCRUDGRSJFXS5FEDWKP2QVANCNFSM44Z4BU6Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
npm run dev -- --host solved my problem. Thanks everyone |
Beta Was this translation helpful? Give feedback.
-
I Have issues when running with --host because it sais "not secure" and some browser features are turned off. I need to access it from my mobile. Does anyone know how to solve that? |
Beta Was this translation helpful? Give feedback.
-
getting |
Beta Was this translation helpful? Give feedback.
-
I got error something like this when it accessed in mobile while in the same network |
Beta Was this translation helpful? Give feedback.
-
It seems like the behavior of the "npm run dev" command has changed. To expose the network address, you now need to use the "--host" flag. For example, you can run "npm run dev -- --host 0.0.0.0" to expose the network address. The change might have been made for security reasons or to streamline the development process. You can refer to the project's documentation or release notes for more details on why this feature was modified. |
Beta Was this translation helpful? Give feedback.
-
Thank you guys for this thread, it's very helpful |
Beta Was this translation helpful? Give feedback.
-
I struggled with this issue today. I wanted to connect from my phone, but it didn't work. I checked the Vite configuration and the firewall configuration in the system. Then I checked on my girlfriend's computer and her phone, and it worked there. It turned out that I accidentally turned off Wi-Fi on my phone, haha. I think the information to check your connection might be useful for someone too. Leave like ❤️ if you experienced same thing 😅 |
Beta Was this translation helpful? Give feedback.
-
I did add --host, and exposed the port in windows firewall settings, and even restarted windows, but still not able to access it. It says - this site can't be reached. I get this in vite output and none works Any suggestions. |
Beta Was this translation helpful? Give feedback.
-
Could also easily insert:
to your |
Beta Was this translation helpful? Give feedback.
-
The best way to config your vite.config.js
|
Beta Was this translation helpful? Give feedback.
-
I use Remix
|
Beta Was this translation helpful? Give feedback.
-
I was having trouble accessing my Vite server from my mobile device, even though both my PC and mobile were connected to the same Wi-Fi network. The server was running on port 5173, but I couldn’t connect to it from my phone. I tried a few things like:
The Issue with the Initial ScriptInitially, my "scripts": {
"dev": "vite --host 0.0.0.0"
} This was supposed to make the server accessible on the network, but it didn't work for me. Despite this, the server would only be accessible locally on my PC, and I couldn't access it from my mobile device. The SolutionAfter trying various methods, I decided to modify the script and change the port. I updated it to: "scripts": {
"dev": "vite --port 3000 --host 0.0.0.0"
} ResultAfter running
It seems the original port 5173 was either blocked or restricted in some way. Changing both the port and the host to |
Beta Was this translation helpful? Give feedback.
The default host now listens to
127.0.0.1
so you only get localhost exposure. It was changed because it is a security concern to expose your file system to external addresses by default.To get the same behaviour as in v2.2, you can use:
Or set
server.host
totrue
in your config.https://vitejs.dev/config/#server-host