Reputation: 2201
I am relatively new to using Google Cloud Platform and created VM instance on GCP.
Could someone please suggest how to set up browser on this instance. I could not find browser option while setting up instance.
Please note that one React app is running on this VM instance so wanted to access it via http://localhost:3000
.
One approach i tried was to allow incoming traffic on VM instance and then access above URL from local machine browser but that is not working as following is the error in local machine browser:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at URL. (Reason: CORS request did not succeed)
Another approach i tried is using command curl localhost:3000
on VM instance itself but its output is as follows:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="/favicon.ico">
<!--
Notice the use of in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.
-->
<script type="text/javascript" src="/static/js/bundle.js"></script></body>
</html>
If browser installation is not correct way then how to test React app running on GCP VM instance?
Upvotes: 1
Views: 1619
Reputation: 466
Unless you are using a non-graphical version of windows server, and considering that all windows servers came with at least Internet explorer available by default, i will assume that your are working on a linux CLI machine (again, graphical version of Linux usually came with Mozilla or Opera browser by default).
As Armando well mentioned in his comment above, it’s necessary to know if your app is internet exposed. If this is the case, there’s no need to setup or install any browser on your VM, you just need to take your VM external IP and your app port and paste it in any browser (like chrome for example) in the same format you paste above but replacing “localhost” with such external IP.
For this to work of course you need to make sure that your instance allows http and https traffic by going to your GCP Console >> Compute Engine >> VM Instances. On the VM Instances page, click on your instance name to see the details, look for the section “Firewall” and see if the checkboxes are marked to “Allow HTTP Traffic” and “Allow HTTPS Traffic”.
If not marked, but still the page will be exposed to the internet, in the same page, beside the title “VM Instance Details” you have an edit button that will allow you to enable such checkmarks.
A Second option is to enable a VNC to get a graphical session of your server, to achieve it follow next post for a Debian distro:
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-debian-9
Or this one if yours is CetOs/RHEL distro:
https://www.linuxtechi.com/install-configure-vnc-server-centos-7-rhel-7/
Or a 3rd easy option is to install a 3rd party software like lynx to browse web sites:
sudo apt install lynx
once installed, just type “lynx” followed by your URL, i.e:
lynx google.com
And it will show you the command line version of google search:
Upvotes: 1