Vite : Application works on localhost:5173 but not on 127.0.0.1:5173 - reactjs

My Vite.js application works normally on http://localhost:5173/ but when I am using http://127.0.0.1:5173/ the app does not work.
I am using an Intel Mac (MacOs: Ventura 13.0.1).
When I tried creating a normal react app, then http://localhost:3000 and 127.0.0.1:3000 both are working the same.
Tried searching a few stackoverflow posts where they asked me run
sudo nano /etc/hosts
And the following line to the end of the file:
127.0.0.1 myapp.local
But that does not solve the issue as well.
My /etc/hosts file:

Try changing myapp.local to localhost in the /etc/hosts file, it should fix it

Related

How send request from react native to local server

I am using android emulator and when i send request to localhost it gives me error. I have tried the forwarding the port also ngrok but none of them worked for me. It always gives me error.
[Error:Network Error].
IN Emulator go to setting->click on Network and Internet ->then select Internet->select available network and then re-run your project and check it will work
Please try http://10.0.2.2:8080 instead of localhost:8080. If you are referring your localhost on your system from the Android emulator then you have to use http://10.0.2.2:8080/ Because Android emulator runs in a Virtual Machine therefore here 127.0.0.1 or localhost will be emulator's own loopback address.
Original Answer Source

browser does not launch on running react project on wsl (zsh)

I am working on a simple react project on Windows 10 Pro. On trying to run the project with wsl with zsh (npm start) everything works, I get warnings and compilation is done without any errors. The issue I am facing is automatic launch of browser from wsl is not happening.
If I manually open localhost:3000 on my chrome after this command everything works but I would like the wsl terminal to launch my browser on npm start automatically just like it does in most of my other terminals and powershell on windows.
What I have tried:
added a export browser property to my .zshrc with path to chrome from here
Added a bsconfig file to root with following code to set open = true as per from here
I have added the ports from 3000-3999 to my firewall so that wsl can access my host (localhost ip). this fixed previous issue where localhost:3000 would show connection refused error.
I would be happy to provide any more details.
I am very new to wsl and zsh and I would really appreciate any help. Thanks

Node.js application wont start on my public IP

I'm SSHing into a linux shell for a school project. Right now, we're trying to set up a react app for a web frontend. We were able to run the app on localhost easily enough, and all of the functionality seems to be good, but I can't figure out how to get this hosted on the public IP of the computer. We've been using yarn to do all of this, though i've tried other things, so here's some cli output.
path/to/thing# yarn start
yarn run v1.22.5
$ react-scripts start
Attempting to bind to HOST environment variable: public.facing.ip.address //This is a website name
If this was unintentional, check that you haven't mistakenly set it in your shell.
Learn more here: //There was a link here but SO formatting wouln't let me keep it.
Could not find an open port at public.facing.ip.address.
Network error message: listen EADDRNOTAVAIL: address not available public.facing.ip.address //numeric
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
root#computer:path/to/thing#
When I run hostname -I, public.facing.ip.address does not appear at all. So that seems like the obvious issue. The catch here is that we are also running jenkins on a separate port of public.facing.ip.address from this same computer. That was much easier to set up, it just came as something I could start as a service using 'systemctl start jenkins' and up it went onto the public facing IP. I set all that up and I can access it just fine, etc. The best I can do with this is modify the HOST variable either in the terminal or the .env file, then yarn starts a development server on localhost (which I can't access since I'm on a different network SSHing into this computer)
How do I make yarn host our webapp on the public facing IP?
open your router page, there should be dmz host option somewhere, point it to your local ip address
My networking inexperience was the culprit. Instead of using HOST=path.to.public.ip, the solution was to use HOST=0.0.0.0.

Project inside webapp tomcat8 does not run in webpage

I am trying to run my application using tomcat8 inside the Apache2 virtual machine, using MacOS.
The IP address is: http://143.167.11.2:8080
and this the view when I run the link on the browser:
I have installed tomcat8 inside this apache2 VM using: apt-get install tomcat8 by following this instruction: https://www.linode.com/docs/development/frameworks/apache-tomcat-on-ubuntu-16-04/
When I run this address http://143.167.11.2:8080 the result is the same, it just shows this same picture . It does not show the tomcat home page.
I have tried to run this: ./startup.sh and inside the terminal and it started.
But when I run the linked address http://143.167.11.2:8080 the result is same, it shows apache home page.
I tried to put my project inside /var/lib/tomcat8/webapps and then tried to run: http://143.167.11.2:8080/visualisation-dataproject.
But the result like below:
Any idea how can I run my project (that I put on the webapps folder) on the web browser?
Apache2 is usually use for PHP project. Tomcat is usually for java project. There are some possibility why you can not run tomcat on the web browser. One of the reason is you have not install tomcat8 properly. Even you have install it, you should check it really work or not. If it work on the VM, maybe the problem when you set the port for tomcat in server.xml.
To check server.xml, try : sudo nano /etc/tomcat8/server.xml, and find <Connector port="8080" protocol="HTTP/1.1 ... line.
And try to change the port 8080 to another port e.g: 8081. Why? to prevent tomcat8 server running with same port with another server such as apache2.
After that try the step on this link: https://askubuntu.com/a/434085/856656 it should work.

create-react-app does not serve boilerplate app

I haven't made any changes, I just run "create-react-app client", then everything runs correctly, I cd into the directory and run "yarn start".
Then I have two problems:
1) It says "Something is already running on port 3000". Unfortunately when I use lsof and netstat, nothing is running on port 3000. I say to run on a different port, and it then attempts to serve the app.
2) Nothing is served on the new port. The browser opens up, the console gives no errors, but nothing gets served to the browser.
node version 8.7.0
yarn version 1.3.2
create-react-app version 1.3.3
OS MacOS
My hosts file was empty, so "localhost" didn't mean anything.
127.0.0.1 localhost fixed it.

Resources