"Invalid Host header" when web app is served inside a VM (Angular2CLI) - angularjs

I am trying to run my web app from inside an Ubuntu 16 64-bit virtual machine. Of course, this means I can't have the host be localhost, so I changed the host in the .angular-cli.json file under defaults:
"defaults": {
"serve": {
"host": "0.0.0.0"
},
"styleExt": "css",
"component": {}
}
When I do npm start and go to the URL of the VM, I get a page saying "Invalid Host header". What am I doing wrong? How can I run the web app and access it correctly?
I am new to Angular and was following this tutorial: https://angular.io/guide/quickstart. I am also using Vagrant.
Any help would be appreciated, thank you!

It turns out I had to use the private_network ip address as the host instead, which is located inside the Vagrantfile on this line:
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.100.5"
Though, this only makes it work locally. If someone else has an answer, it would be greatly appreciated!

host should be 192.168.0.100 (your ubuntu server ip).
maybe you can just edit package.json
add host para in start cmd.
"start": "************* --host 192.168.0.100 ",
and npm start will be ok.

Related

sudo npm run start Admin permissions error?

I am trying to run react application as sudo on port 443 but it is throwing permissions error as follows. I tried running the react script with root privileges too but get the same error.
Command used is
sudo npm run start
Error
? Admin permissions are required to run a server on a port below 1024. Probably:
/Applications/Google Chrome.app/Contents/Frameworks/Google Chrome Framework.framework/Versions/91.0.4472.114/Helpers/Google Chrome Helper.app/Contents/MacOS/Google Chrome Helper --type=utility --utility-sub-type=network.mojom.NetworkService --field-trial-handle=1718379636,2199499938256335430,15968884667410910440,131072 --enable-features=BlockInsecurePrivateNetworkRequests,CookieSameSiteConsidersRedirectChain,CriticalClientHint,CrossOriginEmbedderPolicyCredentialless,CrossOriginIsolated,CrossOriginOpenerPolicyAccessReporting,CrossOriginOpenerPolicyReporting,DocumentPolicyNegotiation,EnableNewCanvas2DAPI,ExperimentalContentSecurityPolicyFeatures,FeaturePolicyForClientHints,LangClientHintHeader,OriginIsolationHeader,OriginPolicy,SchemefulSameSite,UserAgentClientHint --lang=en-US --service-sandbox-type=network --enable-experimental-web-platform-features --metrics-client-id=22a9279b-1648-45cf-a03c-0ce68df69ad5 --shared-files --seatbelt-client=27 (pid 887)
in /
Would you like to run the app on another port instead? (Y/n)
I checked port 443 and it is available to listen. I also wrote a script to listen on port 443 on localhost and it is able to bind on this port as a sudo user. No luck with the react app though.
I was able to run react app earlier in the same laptop but something changed and I don't know what. The error is anyway about permissions but I ruled out this possibility.
I feel it has something to do with Google Chrome Helper which react-scripts is trying to run without Admin Privilege.
Also, it could be some other package I installed which may have caused the issue.
I am at a loss here and am not sure how to debug it further. Googling the problem didn't help either. Any help to debug or fix the issue is greatly appreciated. Thanks in advance.
Mac OS Big Sur - version 11.4
npm version 7.18.1
I was able to get around this issue, by using this package.json command:
{
"scripts": {
"start-https": "sudo PORT=443 HTTPS=true react-scripts start"
}
}
I met the same issue, and solved by downgrading the node version from 16 to 14, don't know why but works.
The only way I found it to work (especially when you install node and npm using nvm) is to call react-scripts directly:
sudo node ./node_modules/.bin/react-scripts start
This assumes you are in the project / repository directory containing .node_modules. Nevertheless, it is different question whether its correct to npm start with sudo. I was just experimenting to run the dev server on port 80 and it was giving error
Admin permissions are required to run a server on a port below 1024.
And I was unable to fix it with various solutions specified on these links: 1, 2, 3, 4. From these links I mostly tried configuration related solutions as I did not wanted to reinstall node (without nvm).

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.

Error: No network specified. Cannot determine current network

Truffle react-box not working as expected with default setup (with ganache and metamask)
I download and run ganache then I followed the first 4 steps in the readme and when I get to truffle migrate it says 'Error: No network specified. Cannot determine current network.' in the console.
On OSX 10.13.3 I went into the truffle.js file in the root folder and changed it to
module.exports = {
networks: {
development: {
host: '127.0.0.1',
port: 7545,
network_id: '*'
}
}
};
npm run start in the terminal and everything works fine. Make sure you have ganache running in the background though.
Also, make sure that the rpc server in ganache matches the host and port in the truffle file you just updated.

hosting on webpack dev server accessing from parallels

I am working on an app that for testing is hosted on web pack dev server.
I am using the following settings in my web pack.config file
devServer: {
host: 'mysite.local.co.uk',
port: '14500'
}
I have the following set in my hosts file on Mac
0.0.0.0 mysite.local.co.uk
I can now access the site on my Mac using http://mysite.local.co.uk:14500
I am trying to use a similar config to access the site from a windows 7 parallels desktop I have created.
I have done the following:
Set parallels network to shared
Set the hosts file windows to
[My Mac IP] mysite.local.co.uk
When I attempt to access the site from parallels I get no response
I have pinged [My Mac IP] and get reply's as would be expected.
I have tried setting host to 0.0.0.0 and as suggested here Github Issue
I am at a loss for how to make this work any suggestions would be greatly accepted
On macOS Mojave, go to Settings -> Sharing to see your Mac's network name.
It should say something like "Computers on your local network can access your computer at: YourComputerName.local". You can also change this name to something easier to remember and type.
On my Mac, this allows me to access my dev server via Parallels, Windows 10 and Chrome over port 8080. Not sure if the port matters.

How to open localhost:8080 in Cloud9 IDE?

I am developing an app engine project (golang) in Cloud9 IDE. For testing in desktop i would go to localhost:8080 in my desktop browser.
In Cloud9, I tried https://workspace-username.c9.io with $PORT set as 8080, but somehow its not working for appengine project. But it is working for normal go web project though.
How do i test app engine application in Cloud9 IDE? or
How do i open http://localhost:8080 in Cloud9 IDE?
Available ports on a hosted Cloud9 workspace
If you're developing a server application, please note that you need
to listen to 0.0.0.0 ($IP) and 8080 ($PORT). Listening to this port
will enable your app to be viewable at https://-.c9users.io
You can also bind to ports 8081, and 8082, which can be accessed by
https://-.c9users.io:8081 and https://-.c9users.io:8082 respectively.
Please note that 8080, 8081, and 8082 are the only available ports on
a hosted Cloud9 workspace.
How to connect to the process running on 'localhost' that is inside of cloud9 server
I see some users are looking for the answer for this, So here is how to do it.
instead of "goapp serve" use "goapp serve -host 0.0.0.0"
credits to Cloud9 support team.
For Google App Engine running Python, the command would be
dev_appserver.py app.yaml --host $IP --port $PORT --admin_host $IP --admin_port 8081
You can also specify the admin host/port. Since Cloud 9 allows access to 8081 and 8082, you can use either of those as your admin ports. For me, the admin console did not open with the Cloud9 preview, but did open in a new tab within my browser.
$IP and $PORT are both environment variables for Cloud 9, with the values of 0.0.0.0 and 8080 respectively.
Edit:
With the most recent gcloud update (March 2018), you don't have to change the IP or PORT, but you do need to figure out how to work around the host whitelisting issue.
My non-ideal workaround is to add a flag to not check for hosts --enable_host_checking=false.
dev_appserver.py app.yaml --enable_host_checking=false
There's an unanswered Cloud 9 post around this issue (link to c9 forum). My guess is that you can add $C9_HOSTNAME as the host, but that doesn't quite work for me.
Interactive Console
If you want to use the interactive console you need to assign the admin port and also use the `--enable_console' flag.
dev_appserver.py app.yaml --enable_host_checking=false --admin_port 8081 --enable_console=true

Resources