Connect to localhost server with second device

560 Views Asked by At

Hello I would like to open my app with another device. I start the local server on my computer. This will run the app on localhost:5173. With ipconf in the command terminal I can find the dynamic IP address of my computer. With my laptop, I enter the address 192.168.0.x:5173 in the browser, but it does not work.

I have searched the internet for a solution and have always found what I have done so far. The only thing I can think of is to set a prot forwarding on the router, but I don't know how.

2

There are 2 best solutions below

0
Razielruss On

Okay here is an explanation of how to access the localhost server with the second computer.

What is written in the question is correct. You also have to set up port forwarding on the router. In the setting, port 80 must be specified and a destination IP address. The destination IP address is the address of the computer on which the server is running.

In order to access the React Vite App with the second computer, the following entry must be added in the package.json:

host": "vite --host". The app must then be started with npm run host. Then it should work.

If it still does not work, then it may be the firewall. You can switch it off to check whether it works. If it does work, then a firewall rule can be added. I did it like in this document https://www.devopinion.com/access-localhost-from-another-computer-on-the-same-network/

0
ASHWIN C On

If you use vite+react then you should update the vite.config.js file with

export default defineConfig({
  plugins: [react()],
  server: {
    host: '0.0.0.0',
  },
})

and run the vite server npm run dev