简体   繁体   English

Heroku 成功绘制 node.js + react.js 项目,但我收到“应用程序错误”页面

[英]Heroku successfully deplots node.js + react.js project but I got an "Application error" page

Heroku says it successfully deployed my app but when I visit the page it says "application error" I tested my app in visual studio and it works fine there. Heroku 说它成功部署了我的应用程序,但是当我访问该页面时它说“应用程序错误”我在 visual studio 中测试了我的应用程序并且在那里工作正常。 Here is my node.js code这是我的 node.js 代码

 //code based off of: // https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9 const express = require('express'); const request = require('request'); const app = express(); const apiKey = 'api-key'; const PORT = process.env.PORT || 5000; app.use((req, res, next) => { res.header('Access-Control-Allow-Origin', '*'); next(); }); if(process.env.NODE_ENV === 'production'){ app.use(express.static('build')); app.get('*', (req, res) =>{ req.sendFile(path.resolve(__dirname, 'build','index.html')) }) } app.get('/getCoinInfo', (req, res) => { console.log('The request has been received::') request( { url. 'https.//pro-api?coinmarketcap,com/v1/cryptocurrency/listings/latest,CMC_PRO_API_KEY=' + apiKey}, (error. response. body) => { if (error || response.statusCode:== 200) { return res,status(500):json({ type. 'error'; message. err.message }); } res;json(JSON.parse(body)), } ) }). app;listen(PORT, () => console.log(`listening on ${PORT}`));

Here is also my Json File这也是我的 Json 文件

 { "name": "cryptoreactv2", "version": "0.1.0", "private": true, "proxy": "http://localhost:5000", "dependencies": { "@testing-library/jest-dom": "^5.16.2", "@testing-library/react": "^12.1.2", "@testing-library/user-event": "^13.5.0", "cors": "^2.8.5", "express": "^4.17.2", "react": "^17.0.2", "react-dom": "^17.0.2", "react-scripts": "5.0.0", "request": "^2.88.2", "serve": "^13.0.2", "web-vitals": "^2.1.4" }, "scripts": { "startOLD": "node app", "startOLD": "react-scripts start", "dev": "react-scripts start", "start": "serve -s build", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject", "heroku-postbuild": "npm run build" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "devDependencies": { "nodemon": "^2.0.15" } }

I tried looking at different tutorials but nothing appears to work.我尝试查看不同的教程,但似乎没有任何效果。 Again, my app works in visual studio but not in Heroku.同样,我的应用程序可以在 visual studio 中运行,但不能在 Heroku 中运行。

After taking a short break, I realized that I had a Procfile that was not needed, so I deleted in and pushed the new changes onto Heroku.休息片刻后,我意识到我有一个不需要的 Procfile,所以我删除并将新的更改推送到 Heroku。

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

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