【发布时间】:2019-08-01 01:10:35
【问题描述】:
我在server.js中写了index.html文件的位置。 但浏览器显示“未找到”。如何正确写入 index.html 文件的位置?
index.html 文件的位置。
(root)client->public->index.html
const express = require('express');
const bodyParser = require('body-parser');
const exphbs = require('express-handlebars');
var nodemailer = require('nodemailer');
const path = require('path');
const app = express();
// Serve static assets in production
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
const port = process.env.PORT || 5001;
app.listen(port, ()=> console.log(`Server started on port ${port}`));
我希望浏览器显示首页,但 Heroku 日志返回以下行:
Error: ENOENT: no such file or directory, stat '/app/client/build/index.html
【问题讨论】:
-
你也可以发布文件夹结构吗?
-
这是文件夹结构。客户端(node_modules、public、resource、src、gitignore、package.json)、package.json、Procfile、server.js
标签: node.js reactjs express heroku