简体   繁体   English

无法访问Heroku上的Web服务器

[英]Unable to access web server on Heroku

I am following this tutorial/guide . 我正在遵循本教程/指南 Locally, it works, using localhost as the domain, and 8080 as the port. 在本地,它可以工作,使用localhost作为域,并使用8080作为端口。

Here's the local configuration: 这是本地配置:

"dashboard" : {
    "oauthSecret": `${process.env.oauthSecret}`,
    "callbackURL": `http://localhost:8080/callback`,
    "sessionSecret": "fakesessionsecret",
    "domain": "localhost",
    "port": 8080
  },

But now, I would like to use the app on Heroku, and access the web dashboard through https://project-name.herokuapp.com or through a custom domain, which I linked already to the DNS provided, in format dashboard.example.com . 但是现在,我想在Heroku上使用该应用程序,并通过https://project-name.herokuapp.com或通过自定义域访问Web仪表板,我已经将其链接到提供的DNS,格式为dashboard.example.com

localhost and/or the port does not work for Heroku, so I'm not sure what to change it to for it to work. localhost和/或端口不适用于Heroku,因此我不确定将其更改为什么才能正常工作。 I have already tried to change the domain to xxx.herokudns.com , port to process.env.PORT , domain to the custom one I set in Heroku - but they all result in the app crashing with status 503 when I visit the URL. 我已经尝试将域更改为xxx.herokudns.com ,将端口更改为process.env.PORT ,将域更改为我在Heroku中设置的自定义域名-但是当我访问该URL时,它们都会导致应用崩溃,状态为503

From what I see, the configuration domains and ports are used in these codes: 从我所看到的,这些代码中使用了配置域和端口:

const express = require("express");
const app = express();
const passport = require("passport");

passport.use(new Strategy({
    clientID: client.appInfo.id,
    clientSecret: config.dashboard.oauthSecret, //from configuration
    callbackURL: config.dashboard.callbackURL, //from configuration
    scope: ["identify", "guilds"]
  }
...
app.locals.domain = config.dashboard.domain;
...
app.listen(client.config.dashboard.port);

So how do I access the web application from Heroku? 那么,如何从Heroku访问Web应用程序呢?

When you get a 503, are you checking your Heroku logs? 收到503时,您是否正在检查Heroku日志? They should provide specific info about what's causing the crash. 他们应提供有关导致崩溃的原因的特定信息。

The domain should be dashboard.example.com and the port should be process.env.PORT . 域应为dashboard.example.com ,端口应为process.env.PORT Better still, use dotenv and a .env file to define your environment variables locally, and use Heroku's "Settings" tab to set the environment variables in production (in this instance, just domainport is already set for you on each app launch). 更好的是,使用dotenv和.env文件在本地定义环境变量,并使用Heroku的“设置”标签在生产环境中设置环境变量(在这种情况下,仅domain –每次应用启动时都已为您设置了port ) 。

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

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