MERN在Heroku不跨浏览器工作

问题描述 投票:0回答:1

我公司开发MERN应用与MLAB,反应,终极版。工作在开发中的罚款。我部署在Heroku上和我用于开发Chrome的正常工作(有反应,终极版的附件)。

问题:它显示了在任何其他浏览器的空白在我的机器,包括在任何其他机器铬。我看着在网络和每个在这个论坛的解决方案,我做的server.js(或app.js)以下。也就是说,在我自己的镶边这个URL(https://servicexpoc.herokuapp.com/)工作正常,但在其他任何它是一个空白页。

if (process.env.NODE_ENV === 'production') {
        // app.use(express.static('client/build')); returns blank page
        // Changed to ...
        app.use('/static', express.static(path.join(__dirname, 'client/build')));
        app.get('*', (req, res) => {
        res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
      });
    }

难道传统...混帐东西(git的添加,提交),然后检查远程连接到Heroku的,也做了'混帐推Heroku的主人。一切都很好...服务器已启动和晒太阳。再一次,它显示在我的铬和工作就像一个魅力...但无处。

以下是我的服务器端的package.json:

    {
      "name": "appname",
      "version": "1.0.0",
      "description": "Developer Connection social media",
      "main": "server.js",
      "scripts": {
      "client-install": "npm install --prefix client",
      "start": "node server.js",
      "server": "nodemon server.js",
      "client": "npm start -prefix client",
      "dev": "concurrently \"npm run server\" \"npm run client\"",
      "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix 
 client && npm run build --prefix client"
  },
      "author": "Jit <[email protected]>",
      "license": "ISC",
      "dependencies": {
      "bcryptjs": "^2.4.3",
      "body-parser": "^1.18.3",
      "concurrently": "^3.6.0",
      "express": "^4.16.3",
      "gravatar": "^1.6.0",
      "jsonwebtoken": "^8.3.0",
      "mongoose": "^5.1.5",
      "passport": "^0.4.0",
      "passport-jwt": "^4.0.0",
      "validator": "^10.3.0"
     }
}

以下是客户端的package.json

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
  "axios": "^0.18.0",
  "classnames": "^2.2.6",
  "jwt-decode": "^2.2.0",
  "moment": "^2.22.2",
  "react": "^16.4.1",
  "react-dom": "^16.4.1",
  "react-moment": "^0.7.7",
  "react-redux": "^5.0.7",
  "react-router-dom": "^4.3.1",
  "react-scripts": "1.1.4",
  "redux": "^4.0.0",
  "redux-thunk": "^2.3.0"
 },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
 },
 "proxy": "http://localhost:5000"
}

我的目录结构:

appName
  client
    public 
      ... index.html (that is the root of react)
    src
      ... this has all the react code
  package.json (client side)
....... SERVER SIDE  
server.js
models  
   ... all models here
routers
   ... all routers here
validations
   ... all validations here
package.json   (SERVER SIDE)
.gitignore

试图按照指示上:https://expressjs.com/en/starter/static-files.html

任何帮助...

node.js reactjs heroku deployment mern
1个回答
0
投票

为了Heroku的呈现,如果你碰巧在自己的Chrome发展已经吞并REDUX DEVTOOLS,请执行以下操作:

常量店= createStore(rootReducer,初始化状态,谱写(applyMiddleware(...中间件),//window.REDUX_DEVTOOLS_EXTENSION && window.REDUX_DEVTOOLS_EXTENSION()//检查下一个THIG工作window.REDUX_DEVTOOLS_EXTENSION window.REDUX_DEVTOOLS_EXTENSION():F = > F));

最初,我迫使铬添加DEVTOOL(如上述,现在评论说代替三元)。 Heroku的,同时建设,并没有无视这一点,也没有它创建一个错误甚至警告。它只是没有渲染(空白)。在上述情况下,这将使你的页面。

© www.soinside.com 2019 - 2024. All rights reserved.