Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 谷歌云平台上的浏览器_Javascript_Reactjs_Google Cloud Platform_Browser - Fatal编程技术网

Javascript 谷歌云平台上的浏览器

Javascript 谷歌云平台上的浏览器,javascript,reactjs,google-cloud-platform,browser,Javascript,Reactjs,Google Cloud Platform,Browser,我对使用Google云平台比较陌生,在GCP上创建了VM实例 有人可以建议如何在这个实例上设置浏览器吗。设置实例时找不到浏览器选项 请注意,此VM实例上正在运行一个React应用程序,因此希望通过http://localhost:3000 我尝试过的一种方法是允许VM实例上的传入流量,然后从本地机器浏览器访问上面的URL,但不起作用,因为以下是本地机器浏览器中的错误: 阻止跨源请求:同源策略不允许读取URL处的远程资源。(原因:CORS请求未成功) 我尝试的另一种方法是在VM实例本身上使用命令c

我对使用Google云平台比较陌生,在GCP上创建了VM实例

有人可以建议如何在这个实例上设置浏览器吗。设置实例时找不到浏览器选项

请注意,此VM实例上正在运行一个React应用程序,因此希望通过
http://localhost:3000

我尝试过的一种方法是允许VM实例上的传入流量,然后从本地机器浏览器访问上面的URL,但不起作用,因为以下是本地机器浏览器中的错误:

阻止跨源请求:同源策略不允许读取URL处的远程资源。(原因:CORS请求未成功)

我尝试的另一种方法是在VM实例本身上使用命令
curl localhost:3000
,但其输出如下:

<!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>


反应应用程序

如果浏览器安装方式不正确,那么如何测试在GCP VM实例上运行的React应用程序?

除非您使用的是非图形化版本的windows server,并且考虑到默认情况下所有windows服务器都至少有可用的Internet explorer,我将假定您在linux CLI机器上工作(同样,默认情况下,Linux的图形版本通常附带Mozilla或Opera浏览器)

正如Armando在上面的评论中提到的,有必要知道你的应用程序是否暴露在互联网上。如果是这种情况,你不需要在你的虚拟机上设置或安装任何浏览器,你只需要将你的虚拟机外部IP和你的应用程序端口粘贴到任何浏览器中(比如chrome)与上面粘贴的格式相同,但将“localhost”替换为此类外部IP

当然,要使其正常工作,您需要确保您的实例允许http和https通信,方法是转到您的。在VM实例页面上,单击您的实例名称以查看详细信息,查找“防火墙”部分,并查看复选框是否标记为“允许http通信”和“允许https通信”

如果未标记,但页面仍将向internet公开,在同一页面中,在标题“VM实例详细信息”旁边有一个编辑按钮,允许您启用此类复选标记

第二个选项是使VNC能够获取服务器的图形会话,以实现此目的,请参阅Debian发行版的下一篇文章:

如果您的是CetOs/RHEL发行版,也可以选择此版本:

或者,第三个简单的选择是安装第三方软件(如lynx)来浏览网站:

sudo apt install lynx
安装后,只需键入“lynx”,然后键入URL,即:

lynx google.com
它将显示google search的命令行版本:


大家好。也许值得添加更多关于您环境的信息。例如,如果您的虚拟机运行Windows或Linux,您是否计划将应用程序公开到internet或仅公开到内部?我想,您可以应用许多解决方案,但我们需要更多地了解您的环境。GCP虚拟机实例是Linux实例-2 4.19.0-16-cloud-amd64#1SMP Debian 4.19.181-1(2021-03-19)x86_64 GNU/Linux,其中React应用程序在3000端口上运行。现在希望通过访问URL查看其外观。