繁体   English   中英

Heroku 无法 GET / 由于“加载资源失败:服务器使用 node.js 响应状态为 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 个小时,尝试了针对类似问题提出的所有解决方案。

heroku 日志

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.

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