【发布时间】:2020-07-14 15:50:32
【问题描述】:
我试图将我的 Express + React 应用程序部署到 Heroku。 Heroku 与我的 Github 帐户成功连接,然后单击“部署分支”导致“您的应用程序已成功部署”。但是当我去查看我的网站时,它显示:
“应用程序错误应用程序发生错误,无法提供您的页面。如果您是应用程序所有者,请查看您的日志以了解详细信息”。
这是我的日志:
Starting process with command `npm start`
> myproject@ start /app
> node backend/index.js
My project SQL server listening on PORT 4000
/app/backend/index.js:22
if (err) throw err;
^
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
还有连接 MySQL 的index.js:
const express = require('express');
const cors = require('cors');
const mysql = require('mysql');
const app = express();
app.use(cors());
app.get('/', (req, res) => {
res.send('go to /my-project to see my project')
});
const pool = mysql.createPool({
connectionLimit: 10,
host: 'localhost',
user: 'root',
password: 'myjs123@',
database: 'my-project',
debug: false
});
pool.getConnection((err, connection) => {
if (err) throw err;
app.get('/my-project', (req, res) => {
connection.query(SELECT_ALL_FACTS_QUERY, (err, results) => {
if (err) {
return res.send(err)
}
else {
return res.json({
data: results
})
};
});
});
});
const SELECT_ALL_FACTS_QUERY = 'SELECT * FROM `my-project`.`my-table`;';
app.listen(4000, () => {
console.log('My project SQL server listening on PORT 4000');
});
我做错了什么以及如何部署它?
【问题讨论】:
标签: node.js reactjs express heroku