简体   繁体   English

将 React Express 和 Node 应用程序部署到 Heroku 代理错误

[英]Deploying React Express and Node app to Heroku Proxy Error

I have successfully in the past launched full stack applications to Heroku by using within the client package.json file.过去,我通过在客户端 package.json 文件中成功启动了 Heroku 的全栈应用程序。

"proxy": " http://localhost:3001 " “代理”:“ http://localhost:3001

Now I am getting an "Invalid Host header" I did fix that error by removing the proxy as well as implementing setupProxy.js file with the following code, but afterwards the app does not call the back end at all and errors out.现在我得到一个“无效的主机头”,我确实通过删除代理以及使用以下代码实现 setupProxy.js 文件来修复该错误,但之后应用程序根本不会调用后端并出现错误。

const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'http://localhost:3001',
      changeOrigin: true,
    })
  );
};

I'm wondering how to fix, or if anything changed recently in Heroku to not allow proxy within the client package.json file?我想知道如何修复,或者最近 Heroku 中是否有任何更改以不允许客户端 package.json 文件中的代理?

It looks like it was a seemingly unrelated fix.看起来这是一个看似无关的修复。 I had to enter in some environment variables within Heroku to allow the server to run.我必须在 Heroku 中输入一些环境变量以允许服务器运行。 Without the variables, I believe the server would stop with errors therefore trickling down and causing many problems.如果没有这些变量,我相信服务器会因错误而停止,因此会慢慢下降并导致许多问题。 So long story short, always remember your environment variables within Heroku.长话短说,永远记住 Heroku 中的环境变量。

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

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