heroku - 使用 create-react-app 时无效的主机头
问题描述
我正在使用 creat-react-app 开发一个应用程序,其中我还使用 Heroku 和 Netlify 来部署该应用程序。我让它工作正常,但突然在请求的资源错误中出现 No 'Access-Control-Allow-Origin' 标头。它还在后面的行上显示“网络错误”。
当我去 Heroku 并打开应用程序时,我得到了 INVALID HOST HEADER。
当我在 heroku 和 netlify 上部署时,它们都成功并且没有显示错误,所以我不确定我做错了什么。
我在 package.json 中使用代理:
"proxy": "http://localhost:5000",
和我的 server/index.js 文件:
const app = express();
dotenv.config();
app.use(cors());
app.use(bodyParser.json({ extended: true }));
app.use('/movements', movementRoutes);
app.get('/', (req, res) => {
res.send('Your one rep maxes, together');
});
const PORT = process.env.PORT || 5000;
mongoose.connect( process.env.CONNECTION_URL )
.then(() => app.listen(PORT, () => console.log(`Server running on port ${PORT}`)))
.catch((error) => console.log(error.message));
到目前为止,我尝试过的是:
删除代理
创建一个 .env.development 文件并添加 HOST=(my heroku app name),但这给了我一个“没有打开端口”的错误。
有人对我做错了什么有建议吗?
解决方案
推荐阅读
- nginx - 是否有一个选项可以用来限制缓存资源在 Nginx 中返回给客户端的次数?
- php - Wordpress:使用 PHP 脚本将短代码插入带有类的 div
- postgresql - 保持同一行的并发更新的完整性
- r - R中的实数和自然数
- php - LARAVEL 查询错误 'SELECT count() as aggregate from posts where posts . 已删除_at 为空'
- python - 从两个不同的列表中删除重复的行?
- python - 在 m+=z 之后程序不执行。为什么会这样?
- fonts - 在 vaadin 8 中用另一种语言书写时加粗
- android - flutter图片可以有相同的文件名吗?
- python-3.x - 将多个字符串变量传递给python3中的查询字符串的最佳方法是什么