在Heroku上部署Mern应用程序时获得空白页

时间:2020-03-21 17:20:34

标签: mern

我的server.js

    const express = require('express');
const path = require('path');
const db = require('./config/db');
const app = express();

// MongoDB
db();

const PORT = process.env.PORT || 5000;

app.use(express.json());

// ... other app.use middleware
app.use(express.static(path.join(__dirname, 'client', 'build')));

// ...
// Right before your app.listen(), add this:
app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, 'client', 'build', 'index.html'));
});

app.use('/api/upload', require('./routes/upload'));
app.use('/api/users', require('./routes/users'));

app.listen(PORT, () => {
    console.log(`App listening on port ${PORT}!`);
});

我的package.json

"heroku-postbuild": "cd client && npm install --only=dev && npm install && npm run build"

我的React服务器是Deploy,但是我不知道为什么我的NODE Server无法正常工作。我尝试使用邮递员从heroku服务器获取GET请求,但无法正常工作。请有人帮助

0 个答案:

没有答案