当我部署 React 应用程序和 json-server 时如何修复 Heroku 上的应用程序错误

问题描述

我一直在尝试使用 json 服务器和 react,但由于某种原因,我在 Heroku 上不断收到应用程序错误。可以使用 json-server 进行测试吗。我已经分享了我的 server.js、文件结构和 package.json

server.js

    const jsonServer = require('json-server');
    const app = jsonServer.create();
    const path = require('path');
    const express = require('express');
    // const middlewares = jsonServer.defaults();
    const router = jsonServer.router('db.json');
    const port = process.env.PORT || 3001;
    
    **app.use('/data',router);
    app.use(express.static(path.join(__dirname,'build')));
    app.get('/*',function (req,res) {
        res.sendFile(path.join(__dirname,'build','index.html'));
    });**
    
    server.listen(port);

我的文件夹结构

----client
    ----node modules
    ----public
    ----src
    ----packgage.json
----db.json
----packgae.json
----server.js

package.json

{
  "name": "music","version": "1.0.0","description": "","main": "server.js","scripts": {
    "test": "echo \"Error: no test specified\" && exit 1","start": "node server.js","json-server": "json-server --watch db.json --port 5000","client": "npm start --prefix client","dev": "concurrently \"npm run json-server\" \"npm run client\"","heroku-postbuild": "npm install --prefix client && npm run build --prefix client"
  },"author": "","license": "ISC","dependencies": {
    "concurrently": "^6.0.2","express": "^4.17.1","json-server": "^0.16.3"
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...