Heroku 自定义 DNS API 路由问题在 Node.js



我在 Heroku 中设置了一个自定义域,效果很好。我可以使用我的应用名称和自定义域访问我的网站。我可以使用标准 Heroku URL 访问路由,但不能使用自定义域。

例如:

工程:

https://{myappname}.herokuapp.com
https://{myappname}.herokuapp.com/callback
https://{customdomain}.com

不起作用:

https://{customdomain}.com/callback

服务器配置:

const express = require("express");
const path = require("path");;
const callback = require("./callback");
const app = express();
// Body parser middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// Serve static assets if in production
 if (process.env.NODE_ENV === "production") {
  app.use("/callback", callback);
// Set static folder
  app.use(express.static("client/build"));
  app.get("*", (req, res) => {
   res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
 });
}
// Init server/port
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server running on port ${port}`));
我知道

为时已晚,但我正在为那些将来面临这个问题的人写作。

我也面临这个问题,并通过这个问题解决了。

不工作

https://{customdomain}.com/callback

这对我有用。

https://www.{customdomain}.com/callback
我想

通了,这很简单,我觉得很愚蠢,但是如果有人遇到同样的问题,我会在这里回答这个问题。

问题:

我有一个名为 Callback 的 React 路由/组件。这个 React 组件调用了一个 Node.js 路由,也称为 Callback,它处理信息然后重定向到一个新的 React 路由/组件。

简单的解决方法是将我的 React 路由/组件更改为 callbackPage,将我的 Node.js 路由保留为回调。

所以总而言之,我有一个与服务器 API 路由同名的网页 URL。 当我访问此页面时,不是呈现页面,而是运行 API 路由,基本上什么都不做并且超时。我仍然对为什么它适用于我的应用程序 URL 而不是我的自定义域感到困惑。

最新更新