如何修复内部服务器错误?- Google Cloud

How do I fix an Internal Server Error?- Google Cloud

我在 Google Cloud Platform 上学习本教程,发现 SIMPLE 应用程序在端口 8080 上成功启动,但是当我转到浏览器从外部查看它时,出现内部服务器错误.该教程可以在这里找到: https://cloud.google.com/appengine/docs/standard/nodejs/building-app/deploying-web-service 我正在使用 GCP 云 shell 终端使用 Win8.1。

我还尝试更新我的 npm 包,将我的 yaml、nodejs 文件移动到下一个更高的目录以及删除下一个更高的目录中的 package.json。就像我说的,端口 8080 可以出现并登录到终端,但不会出现在浏览器中。我的package.json如下:

{
  "name": "express",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}

我的 app.yaml 文件是

runtime: nodejs10

我的 server.js 文件是

//this is a test by MP2
// date of use : 2020-0601
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Hello from App Engine!');
});

// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}...`);
});

任何帮助都会很棒,因为我是 google 云的新手。同样有趣的是,最新版本的 express 安装在下一个更高的文件夹中,而不是安装在所需 JSON 所在的当前文件夹中。 (并且无法更新)谢谢。 -MP

看来这是因为package.json中没有明确的依赖:

"dependencies": {
    "express": "^4.17.1"
  }

我已经复制了所有步骤并且成功了。教程中有4.16.3版本,我有不同,因为我用的是npm install express -s,它自动添加版本到package.json。但是它也适用于我这边的 4.16.3。

希望对您有所帮助!