繁体   English   中英

如何在用户访问应用URL时在Google App Engine上部署node.js应用以便加载?

[英]How to deploy node.js app on Google App Engine so it loads when user goes to app URL?

我是Google App Engine的新手,并且有一个我正在从GitHub存储库中部署的node.js应用程序。 目前,我似乎不得不手动输入一些步骤来预览应用程序,并且当我尝试使用“ gcloud app deploy”进行部署时,服务器仅抛出500错误。 我想发生的事情是“ gcloud应用程序部署”真正起作用了。 大概这意味着无论我是否登录到Google Cloud Services,都要去lucidnodes-dev.appspot.com实际运行该应用程序。

在玩了dockerfiles两天之后,我在哭叔叔。 我需要帮助。

我正在运行的手动步骤来自Google Cloud Shell内部:

cd LucidNodes // Enter the directory where the app files live
node index.js

返回:

LucidNodes listening on port 3000

不出所料,当我在端口3000上运行Web Preview时,我可以看到该应用程序正在运行。

这是我的服务器代码:

server.js文件:

const express = require('express');
const path = require('path');
const url = require('url');

var init = function( app, prt ){

    app.listen( prt, () => console.log('LucidNodes listening on port ' , prt ));
};

exports.init = init;

和index.js文件:

const server = require('./server');
const fs = require('fs');
const express = require('express');
const path = require('path');
const serveStatic = require('serve-static');
const serveIndex = require('serve-index');
const staticPaths = require('./defineStaticPaths');
const htmlMethods = require('./js/htmlMethods');  // import custom methods for handling HTML
const app = express();
const routes = require('./routes');

staticPaths.defineStaticPaths( app );
app.use( routes );

server.init( app, 8080 );

请注意,我已将应用程序的本地实例和GitHub实例上的端口更改为8080。我不确定更改端口号是否可以解决部署和运行应用程序时出现的500错误问题,但我也无法获得GAE上的应用程序实例从GitHub存储库进行更新,因此该应用程序仍在GAE的3000端口上运行,因此也偏离了dockerfiles的位置,到目前为止,这是又一次学习过程的混乱,但是一次我要做一件事假设。

所以...我想做的是让我在调用lucidnodes-dev.appspot.com时实际部署并运行该应用程序。 怎么做?

谢谢您的帮助。

部署到App Engine时,请确保:

  • 应用程式的根目录中有格式正确且有效的app.yaml档案
  • 从相同的根目录运行命令glcoud app deploy
  • package.json包含script字段,指示App Engine安装依赖项并运行网络服务器:

"scripts": {
  "start": "node index.js"
}

如果您未在package.json包含此内容,则该应用程序会继续尝试在本地服务器上进行部署,这当然是行不通的。 无论如何,您看到网站的事实很可能是由于该应用程序的缓存版本或新的部署失败后仍在运行的先前版本。

您要在标准环境还是灵活环境中进行部署?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM