Node.js 我的Heroku页面上出现应用程序错误,甚至我的应用程序构建成功

Node.js 我的Heroku页面上出现应用程序错误,甚至我的应用程序构建成功,node.js,heroku,passport.js,Node.js,Heroku,Passport.js,在MongoDB/Atlas数据库系统上创建。我在本地成功运行了我的应用程序,但当我将应用程序推送到Heroku时,会收到一条应用程序错误消息,消息如下: 应用程序错误 应用程序中出现错误,无法访问您的页面 服务。如果您是应用程序所有者,请查看日志以了解详细信息。 您可以使用以下命令从Heroku CLI执行此操作 heroku原木——尾巴 当我查看日志时: 2021-05-10T13:47:26.214536+00:00 heroku[web.1]: State changed from cr

在MongoDB/Atlas数据库系统上创建。我在本地成功运行了我的应用程序,但当我将应用程序推送到Heroku时,会收到一条应用程序错误消息,消息如下:

应用程序错误

应用程序中出现错误,无法访问您的页面 服务。如果您是应用程序所有者,请查看日志以了解详细信息。 您可以使用以下命令从Heroku CLI执行此操作

heroku原木——尾巴

当我查看日志时:

2021-05-10T13:47:26.214536+00:00 heroku[web.1]: State changed from crashed to starting
2021-05-10T13:47:30.291660+00:00 heroku[web.1]: Starting process with command `node app.js`
2021-05-10T13:47:34.377424+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2021-05-10T13:47:34.377459+00:00 app[web.1]: designed for a production environment, as it will leak
2021-05-10T13:47:34.377460+00:00 app[web.1]: memory, and will not scale past a single process.
2021-05-10T13:47:34.430435+00:00 app[web.1]: /app/node_modules/passport-oauth2/lib/strategy.js:86
2021-05-10T13:47:34.430437+00:00 app[web.1]: if (!options.clientID) { throw new TypeError('OAuth2Strategy requires a clientID option'); }
2021-05-10T13:47:34.430438+00:00 app[web.1]: ^
2021-05-10T13:47:34.430439+00:00 app[web.1]:
2021-05-10T13:47:34.430439+00:00 app[web.1]: TypeError: OAuth2Strategy requires a clientID option
2021-05-10T13:47:34.430439+00:00 app[web.1]: at Strategy.OAuth2Strategy (/app/node_modules/passport-oauth2/lib/strategy.js:86:34)
2021-05-10T13:47:34.430440+00:00 app[web.1]: at new Strategy (/app/node_modules/passport-google-oauth20/lib/strategy.js:52:18)
2021-05-10T13:47:34.430440+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:60:14)
2021-05-10T13:47:34.430441+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2021-05-10T13:47:34.430441+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2021-05-10T13:47:34.430442+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:928:32)
2021-05-10T13:47:34.430442+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:769:14)
2021-05-10T13:47:34.430443+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
2021-05-10T13:47:34.430443+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2021-05-10T13:47:34.513199+00:00 heroku[web.1]: Process exited with status 1
2021-05-10T13:47:34.609472+00:00 heroku[web.1]: State changed from starting to crashed
2021-05-10T13:47:35.401133+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=radiant-lowlands-39265.herokuapp.com request_id=04ac407e-ed22-4211-8600-a326bdc1d6c8 fwd="82.222.132.243" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T13:47:35.696159+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=radiant-lowlands-39265.herokuapp.com request_id=11a57d28-d3c5-4a7a-8f2d-6187ac3997ec fwd="82.222.132.243" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T14:08:33.993147+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=radiant-lowlands-39265.herokuapp.com request_id=6d9f98e3-cfe2-40b2-a68e-bbac56a743f2 fwd="82.222.132.243" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T14:08:34.290006+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=radiant-lowlands-39265.herokuapp.com request_id=0c1a084b-0286-4204-8e13-3413bf93e5ac fwd="82.222.132.243" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T14:14:27.859879+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=radiant-lowlands-39265.herokuapp.com request_id=121f0bcf-5253-40d3-91fb-d5421ec0e4d8 fwd="82.222.132.243" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T14:14:28.345855+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=radiant-lowlands-39265.herokuapp.com request_id=44bd06c7-dbee-48f3-8389-211ccd2d3ee1 fwd="82.222.132.243" dyno= connect= service= status=503 bytes= protocol=https
2021-05-10T13:47:26.214536+00:00 heroku[web.1]:状态从崩溃变为启动
2021-05-10T13:47:30.291660+00:00 heroku[web.1]:使用命令'node app.js启动进程`
2021-05-10T13:47:34.377424+00:00应用程序[web.1]:警告:connect.session()MemoryStore不可用
2021-05-10T13:47:34.377459+00:00应用程序[web.1]:专为生产环境设计,因为它会泄漏
2021-05-10T13:47:34.377460+00:00应用程序[web.1]:内存,并且不会超过单个进程。
2021-05-10T13:47:34.430435+00:00应用程序[web.1]:/app/node_modules/passport-oauth2/lib/strategy.js:86
2021-05-10T13:47:34.430437+00:00应用程序[web.1]:如果(!options.clientID){throw new TypeError('OAuth2Strategy需要clientID选项');}
2021-05-10T13:47:34.430438+00:00应用程序[web.1]:^
2021-05-10T13:47:34.430439+00:00应用程序[web.1]:
2021-05-10T13:47:34.430439+00:00应用程序[web.1]:类型错误:OAuth2Strategy需要clientID选项
2021-05-10T13:47:34.430439+00:00应用程序[web.1]:at Strategy.OAuth2Strategy(/app/node_modules/passport-oauth2/lib/Strategy.js:86:34)
2021-05-10T13:47:34.430440+00:00应用程序[web.1]:在新策略中(/app/node_modules/passport-google-oauth20/lib/Strategy.js:52:18)
2021-05-10T13:47:34.430440+00:00应用程序[web.1]:at对象。(/app/app.js:60:14)
2021-05-10T13:47:34.430441+00:00应用程序[web.1]:at模块编译(internal/modules/cjs/loader.js:1063:30)
2021-05-10T13:47:34.430441+00:00应用程序[web.1]:at Object.modules._extensions..js(internal/modules/cjs/loader.js:1092:10)
2021-05-10T13:47:34.430442+00:00应用程序[web.1]:at Module.load(internal/modules/cjs/loader.js:928:32)
2021-05-10T13:47:34.430442+00:00应用程序[web.1]:at Function.Module.\u load(内部/modules/cjs/loader.js:769:14)
2021-05-10T13:47:34.430443+00:00应用程序[web.1]:位于Function.executeUserEntryPoint[作为runMain](内部/modules/run_main.js:72:12)
2021-05-10T13:47:34.430443+00:00应用程序[web.1]:位于内部/main/run\u main\u模块。js:17:47
2021-05-10T13:47:34.513199+00:00 heroku[web.1]:进程已退出,状态为1
2021-05-10T13:47:34.609472+00:00 heroku[web.1]:状态从开始更改为崩溃
2021-05-10T13:47:35.401133+00:00 heroku[路由器]:at=错误代码=H10 desc=“应用程序崩溃”方法=GET path=“/”主机=radiant-lowlands-39265.herokuapp.com请求\u id=04ac407e-ed22-4211-8600-a326bdc1d6c8 fwd=“82.222.132.243”dyno=connect=service=status=503字节=protocol=https
2021-05-10T13:47:35.696159+00:00 heroku[路由器]:at=错误代码=H10 desc=“应用程序崩溃”方法=GET path=“/favicon.ico”主机=radiant-lowlands-39265.herokuapp.com请求id=11a57d28-d3c5-4a7a-8f2d-6187ac3997ec fwd=“82.222.132.243”dyno=connect=service=status=503字节=protocol=https
2021-05-10T14:08:33.993147+00:00 heroku[路由器]:at=错误代码=H10 desc=“应用程序崩溃”方法=GET path=“/”主机=radiant-lowlands-39265.herokuapp.com请求id=6d9f98e3-cfe2-40b2-a68e-bbac56a743f2 fwd=“82.222.132.243”dyno=connect=service=status=503字节=protocol=https
2021-05-10T14:08:34.290006+00:00 heroku[路由器]:at=错误代码=H10 desc=“应用程序崩溃”方法=GET path=“/favicon.ico”主机=radiant-lowlands-39265.herokuapp.com请求id=0c1a084b-0286-4204-8e13-3413bf93e5ac fwd=“82.222.132.243”dyno=connect=service=status=503字节=protocol=https
2021-05-10T14:14:27.859879+00:00 heroku[路由器]:at=错误代码=H10 desc=“App crash”方法=GET path=“/”主机=radiant-lowlands-39265.herokuapp.com请求id=121f0bcf-5253-40d3-91fb-d5421ec0e4d8 fwd=“82.222.132.243”dyno=connect=service=status=503字节=protocol=https
2021-05-10T14:14:28.345855+00:00 heroku[路由器]:at=错误代码=H10 desc=“应用程序崩溃”方法=获取路径=“/favicon.ico”主机=辐射低地-39265.herokuapp.com请求id=44bd06c7-dbee-48f3-8389-211ccd2d3ee1 fwd=“82.222.132.243”动态连接=服务=状态=503字节=协议=https
在计算机上运行时,我没有Procfile问题或其他一些错误。我试图用我的heroku网址更改app.js和Google云平台中的Google Strategy callbackURL地址。但它不再起作用了。我不明白


提前感谢您的帮助。

问题是您的应用程序找不到
谷歌客户端ID

TypeError:OAuth2Strategy需要clientID选项

您似乎没有在Heroku中正确配置
.env
变量。解决方案非常简单

  • DOTENV方法
  • 如果您以这种方式定义了
    .env

    MONGO_URL="xxx.....xxx"
    GOOGLE_CLIENT_ID="xx......xxx"
    GOOGLE_CLIENT_SECRET="xxx.....xxx"
    
    在您的
    passport设置
    db设置
    中,您使用的是
    dotenv
    as

    require('dotenv').config();
    .
    .
    .
    passport.use(
      new GoogleStrategy
      (
        {
          clientID : process.env.GOOGLE_CLIENT_ID,
          clientSecret : process.env.GOOGLE_CLIENT_SECRET,
          callbackURL : '/auth/google/callback'
        },
    .
    .
    .
    
    然后,您必须在计算机上的项目根目录中声明了一个
    .env
    文件

    您的
    .gitignore
    文件可能会提到
    .env
    ,因为这是执行此操作的标准方式(您不会将env变量推送到公共/团队存储库)

    它在您的计算机上工作的原因是,该应用程序具有环境变量的上下文。在
    Heroku
    中,由于
    .env
    文件不存在,应用程序不知道在哪里可以找到它们

    您所要做的就是将环境变量添加到Heroku。只需进入Heroku仪表板中的设置,进入配置变量菜单。按如下所示的格式添加环境变量。重新启动dyno

    这会解决你的问题

  • 非DOTENV方法
  • 如果您使用任意文件,例如
    keys.js
    或导出相应机密的文件。例如

    const keys = require('../config/keys');
    .
    .
    .
    passport.use(
      new GoogleStrategy
      (
        {
          clientID : keys.googleClientID,
          clientSecret : keys.googleClientSecret,
          callbackURL : '/auth/google/callback'
        },
    .
    .
    .
    
    如果您使用的是conf