Heroku应用程序未在少数浏览器上加载

时间:2018-09-22 07:43:25

标签: node.js reactjs express heroku cloud

我通过CLI在Heroku上部署了Node.js应用程序。我遵循的步骤是

 Git add .
 Git commit -am "message"
 git heroku push master
 heroku open

我没有收到任何错误,当我运行heroku open时,该应用程序正在我的浏览器上运行。问题是,当我尝试使用其他浏览器或通过移动浏览器运行它时,它没有加载。

这是网址:https://smit21.herokuapp.com/

Heroku日志:

2018-09-22T10:45:10.910105+00:00 heroku[web.1]: State changed from starting to up
2018-09-22T10:45:11.024839+00:00 app[web.1]: mongo is successfully Connected
2018-09-22T10:45:11.730224+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=3da0a9c2-6a20-4f07-9832-03384d0030f0 fwd="130.217.199.41" dyno=web.1 connect=1ms service=15ms status=304 bytes=149 protocol=https
2018-09-22T10:45:22.179407+00:00 heroku[router]: at=info method=GET path="/style.css" host=smit21.herokuapp.com request_id=9e8e12f2-3a10-4737-ad59-5a80fc543e15 fwd="130.217.199.41" dyno=web.1 connect=0ms service=22ms status=200 bytes=1671 protocol=https
2018-09-22T10:45:22.467080+00:00 heroku[router]: at=info method=GET path="/service-worker.js" host=smit21.herokuapp.com request_id=23c73ab0-c7dc-4795-8071-96f227c25de7 fwd="130.217.199.41" dyno=web.1 connect=0ms service=6ms status=200 bytes=1671 protocol=https
2018-09-22T10:46:42.380939+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=3d720461-a453-4406-ab50-e619e4a1ca17 fwd="130.217.199.41" dyno=web.1 connect=1ms service=4ms status=304 bytes=149 protocol=https
2018-09-22T11:20:22.770459+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=12c5acba-bf57-4fff-b105-872666b2cedb fwd="130.217.252.116" dyno=web.1 connect=1ms service=3ms status=200 bytes=205 protocol=http
2018-09-22T11:20:23.078071+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=smit21.herokuapp.com request_id=b4012891-eeb7-4475-93e0-42b95464b751 fwd="130.217.252.116" dyno=web.1 connect=1ms service=11ms status=200 bytes=1671 protocol=http
2018-09-22T11:21:23.714105+00:00 heroku[web.1]: Idling
2018-09-22T11:21:23.714612+00:00 heroku[web.1]: State changed from up to down
2018-09-22T11:21:24.902989+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-22T11:21:25.009609+00:00 heroku[web.1]: Process exited with status 143
2018-09-22T12:19:21.492774+00:00 heroku[web.1]: Unidling
2018-09-22T12:19:21.493013+00:00 heroku[web.1]: State changed from down to starting
2018-09-22T12:19:31.538143+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-22T12:19:34.484663+00:00 app[web.1]:
2018-09-22T12:19:34.484689+00:00 app[web.1]: > connectify@1.0.0 start /app
2018-09-22T12:19:34.484691+00:00 app[web.1]: > node server.js
2018-09-22T12:19:34.484692+00:00 app[web.1]:
2018-09-22T12:19:36.922548+00:00 heroku[web.1]: State changed from starting to up
2018-09-22T12:19:36.806116+00:00 app[web.1]: (node:21) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2018-09-22T12:19:36.808856+00:00 app[web.1]: server running on ${port}
2018-09-22T12:19:37.512586+00:00 app[web.1]: mongo is successfully Connected
2018-09-22T12:19:37.644321+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=ee35c390-7a01-47cd-a735-fbc0a09dfa17 fwd="67.81.155.224" dyno=web.1 connect=1ms service=33ms status=200 bytes=205 protocol=https
2018-09-22T12:19:38.625988+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=smit21.herokuapp.com request_id=59431a7d-0435-482e-be56-bc40ec0d7040 fwd="67.81.155.224" dyno=web.1 connect=1ms service=18ms status=200 bytes=1671 protocol=https
2018-09-22T12:37:21.169018+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=a7f0cd4d-564d-4b2c-b2f5-c6b447cf113d fwd="42.113.162.220" dyno=web.1 connect=0ms service=8ms status=200 bytes=205 protocol=https
2018-09-22T12:37:21.688111+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=smit21.herokuapp.com request_id=e942379d-0505-4c52-8a79-06774538178a fwd="42.113.162.220" dyno=web.1 connect=0ms service=6ms status=200 bytes=1671 protocol=https
2018-09-22T13:12:41.189319+00:00 heroku[web.1]: Idling
2018-09-22T13:12:41.189770+00:00 heroku[web.1]: State changed from up to down
2018-09-22T13:12:42.083740+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-22T13:12:42.244254+00:00 heroku[web.1]: Process exited with status 143
2018-09-22T13:40:40.011490+00:00 heroku[web.1]: Unidling
2018-09-22T13:40:40.011737+00:00 heroku[web.1]: State changed from down to starting
2018-09-22T13:40:49.782284+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-22T13:40:52.738181+00:00 app[web.1]:
2018-09-22T13:40:52.738215+00:00 app[web.1]: > connectify@1.0.0 start /app
2018-09-22T13:40:52.738216+00:00 app[web.1]: > node server.js
2018-09-22T13:40:52.738217+00:00 app[web.1]:
2018-09-22T13:40:56.345158+00:00 app[web.1]: (node:21) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2018-09-22T13:40:56.347202+00:00 app[web.1]: server running on ${port}
2018-09-22T13:40:56.727105+00:00 heroku[web.1]: State changed from starting to up
2018-09-22T13:40:57.065561+00:00 app[web.1]: mongo is successfully Connected
2018-09-22T13:40:58.175235+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=11684ba9-34ff-4e3c-b80d-bb4738826fba fwd="185.20.6.43" dyno=web.1 connect=1ms service=27ms status=200 bytes=205 protocol=https
2018-09-22T14:13:38.051816+00:00 heroku[web.1]: Idling
2018-09-22T14:13:38.052343+00:00 heroku[web.1]: State changed from up to down
2018-09-22T14:13:39.140424+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-22T14:13:39.513941+00:00 heroku[web.1]: Process exited with status 143
2018-09-22T17:49:30.699850+00:00 heroku[web.1]: Unidling
2018-09-22T17:49:30.700095+00:00 heroku[web.1]: State changed from down to starting
2018-09-22T17:49:30.712308+00:00 heroku[web.1]: Unidling
2018-09-22T17:49:30.712582+00:00 heroku[web.1]: State changed from down to starting
2018-09-22T17:49:40.987766+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-22T17:49:43.759282+00:00 app[web.1]:
2018-09-22T17:49:43.759314+00:00 app[web.1]: > connectify@1.0.0 start /app
2018-09-22T17:49:43.759315+00:00 app[web.1]: > node server.js
2018-09-22T17:49:43.759316+00:00 app[web.1]:
2018-09-22T17:49:46.124612+00:00 app[web.1]: (node:21) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2018-09-22T17:49:46.126979+00:00 app[web.1]: server running on ${port}
2018-09-22T17:49:46.522505+00:00 heroku[web.1]: State changed from starting to up
2018-09-22T17:49:46.644735+00:00 app[web.1]: mongo is successfully Connected
2018-09-22T17:49:48.917314+00:00 heroku[router]: at=info method=GET path="/robots.txt" host=smit21.herokuapp.com request_id=903a4039-97bc-4828-812b-f1acc2cdc513 fwd="37.170.118.162" dyno=web.1 connect=0ms service=68ms status=200 bytes=1671 protocol=https
2018-09-22T17:49:48.876338+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=9e23b162-b656-447f-a89e-ae5130b3b8bc fwd="37.170.118.162" dyno=web.1 connect=1ms service=31ms status=200 bytes=205 protocol=https
2018-09-22T17:49:51.070701+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=smit21.herokuapp.com request_id=3aaa52db-476e-411f-b6aa-8158dff352cd fwd="37.170.118.162" dyno=web.1 connect=0ms service=8ms status=200 bytes=1671 protocol=https
2018-09-22T18:27:03.807779+00:00 heroku[web.1]: Idling
2018-09-22T18:27:03.808281+00:00 heroku[web.1]: State changed from up to down
2018-09-22T18:27:04.892238+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-22T18:27:05.038741+00:00 heroku[web.1]: Process exited with status 143
2018-09-22T22:01:22.982040+00:00 heroku[web.1]: Unidling
2018-09-22T22:01:22.982330+00:00 heroku[web.1]: State changed from down to starting
2018-09-22T22:01:33.438308+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-22T22:01:36.517339+00:00 app[web.1]:
2018-09-22T22:01:36.517389+00:00 app[web.1]: > connectify@1.0.0 start /app
2018-09-22T22:01:36.517391+00:00 app[web.1]: > node server.js
2018-09-22T22:01:36.517392+00:00 app[web.1]:
2018-09-22T22:01:39.339911+00:00 app[web.1]: (node:21) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2018-09-22T22:01:39.348746+00:00 app[web.1]: server running on ${port}
2018-09-22T22:01:39.761169+00:00 heroku[web.1]: State changed from starting to up
2018-09-22T22:01:39.933342+00:00 app[web.1]: mongo is successfully Connected
2018-09-22T22:01:41.162080+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=d176ed5c-f629-4964-8e78-2bb73b521af3 fwd="185.20.6.141" dyno=web.1 connect=0ms service=26ms status=200 bytes=205 protocol=https
2018-09-22T22:36:02.306389+00:00 heroku[web.1]: Idling
2018-09-22T22:36:02.306919+00:00 heroku[web.1]: State changed from up to down
2018-09-22T22:36:03.163997+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-22T22:36:03.277923+00:00 heroku[web.1]: Process exited with status 143
2018-09-23T00:13:07.000615+00:00 heroku[web.1]: Unidling
2018-09-23T00:13:07.000863+00:00 heroku[web.1]: State changed from down to starting
2018-09-23T00:13:12.849997+00:00 heroku[web.1]: Starting process with command `npm start`
2018-09-23T00:13:14.641841+00:00 app[web.1]:
2018-09-23T00:13:14.641858+00:00 app[web.1]: > connectify@1.0.0 start /app
2018-09-23T00:13:14.641860+00:00 app[web.1]: > node server.js
2018-09-23T00:13:14.641861+00:00 app[web.1]:
2018-09-23T00:13:15.926398+00:00 app[web.1]: (node:21) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
2018-09-23T00:13:15.927682+00:00 app[web.1]: server running on ${port}
2018-09-23T00:13:16.612593+00:00 heroku[web.1]: State changed from starting to up
2018-09-23T00:13:16.526867+00:00 app[web.1]: mongo is successfully Connected
2018-09-23T00:13:19.158301+00:00 heroku[router]: at=info method=GET path="/" host=smit21.herokuapp.com request_id=1753b2d3-291f-4cc4-a02d-184ed39337e9 fwd="24.87.72.248" dyno=web.1 connect=0ms service=10ms status=200 bytes=205 protocol=https
2018-09-23T00:13:19.821530+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=smit21.herokuapp.com request_id=a4270213-9ac1-4e68-827f-ea7e9ac365ba fwd="24.87.72.248" dyno=web.1 connect=0ms service=13ms status=200 bytes=1671 protocol=https
2018-09-23T00:49:06.417379+00:00 heroku[web.1]: Idling
2018-09-23T00:49:06.417954+00:00 heroku[web.1]: State changed from up to down
2018-09-23T00:49:07.535197+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-23T00:49:07.751341+00:00 heroku[web.1]: Process exited with status 143

尝试运行heroku open时的屏幕截图

enter image description here

server.js

const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const passport = require('passport');
const path = require('path');

const users = require('./routes/api/users');
const profile = require('./routes/api/profile');
const posts = require('./routes/api/posts');

const app = express();

// Body parser middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

// DB Config
const db = require('./config/keys').mongoURI;

// Connect to MongoDB
mongoose
  .connect(db)
  .then(() => console.log('MongoDB Connected'))
  .catch(err => console.log(err));

// Passport middleware
app.use(passport.initialize());

// Passport Config
require('./config/passport')(passport);

// Use Routes
app.use('/api/users', users);
app.use('/api/profile', profile);
app.use('/api/posts', posts);

// Server static assets if 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 || 5000;

app.listen(port, () => console.log(`Server running on port ${port}`));

package.json

"heroku-postbuild":
      "NPM_CONFIG_PRODUCTION=false npm install --prefix frontend && npm run build --prefix frontend"

1 个答案:

答案 0 :(得分:0)

我相信您遇到的错误与我的错误相同,并且与redux开发工具有关。我的应用程序在chrome浏览器上运行良好,但是ti在未安装redux开发工具的其他浏览器中无法打开。

要解决此问题,我刚刚在我的redux商店中注释掉了Redux devtool的行:

const store = createStore( rootReducer, initialState, compose( applyMiddleware(...middleware) // window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() ) );

之后,我的应用程序可在所有浏览器中使用。