[英]Deploying a Node.js React App, on CPanel - 'Failed to load resource: the server responded with a status of 404 ()'
[英]Heroku cannot GET / due to 'failed to load resource: server responded with status of 404' using node.js
在节点 server.js 上本地工作
server.js 代码:
const express = require('express');
const path = require('path');
const db = require('./db/db.json'); //*db = database
const PORT = process.env.PORT || 3001;
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static('public'));
app.get('/*/', (req, res) => {
res.sendFile(path.join(__dirname), './public/index.html')
})
//TEXT EDIT: this is at the bottom of the server.js
app.listen(PORT, () => {
console.log(`Port is live http://localhost:3001`)
})
package.json:
{
"dependencies": {
"express": "^4.18.1"
},
"scripts": {
"start": "node Develop/server.js"
}
}
在堆栈溢出上花费了近 4 个小时,尝试了针对类似问题提出的所有解决方案。
app.get('/*/', (req, res) => {
res.sendFile(path.join(__dirname), './public/index.html')
})
变成:
app.get('/*/', (req, res) => {
res.sendFile(path.join(__dirname, './public/index.html')
})
现在得到一个不同的错误,但至少它是新的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.