【发布时间】:2021-04-23 15:31:12
【问题描述】:
我对使用 Google Cloud Platform 并在 GCP 上创建 VM 实例比较陌生。
有人可以建议如何在此实例上设置浏览器。设置实例时找不到浏览器选项。
请注意,一个 React 应用程序正在此 VM 实例上运行,因此希望通过 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 或 Linux,您打算将应用程序公开到 Internet 还是仅在内部?在我看来,您可以应用许多解决方案,但我们需要更多地了解您的环境。
-
GCP VM 实例是 Linux instance-2 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 运行 React 应用程序的 GNU/Linux在 3000 端口。现在想通过访问 URL 来看看它的样子。
标签: javascript reactjs google-cloud-platform browser