将Node.js应用程序部署到Heroku

时间:2020-01-20 23:44:14

标签: node.js react-native heroku

我正在尝试在heroku上部署我的nodejs应用程序。构建成功,但是出现以下错误:

2020-01-20T23:39:44.000000+00:00 app[api]: Build succeeded
2020-01-20T23:39:46.924595+00:00 heroku[web.1]: Starting process with command `npm install --only=dev && npm run client-install && npm run dev`
2020-01-20T23:39:50.661227+00:00 app[web.1]: npm WARN jackpot@1.0.0 No repository field.
2020-01-20T23:39:50.661677+00:00 app[web.1]:
2020-01-20T23:39:50.704813+00:00 app[web.1]: audited 530 packages in 1.693s
2020-01-20T23:39:50.833913+00:00 app[web.1]:
2020-01-20T23:39:50.833917+00:00 app[web.1]: 4 packages are looking for funding
2020-01-20T23:39:50.833919+00:00 app[web.1]: run `npm fund` for details
2020-01-20T23:39:50.833921+00:00 app[web.1]:
2020-01-20T23:39:50.834704+00:00 app[web.1]: found 0 vulnerabilities
2020-01-20T23:39:50.834706+00:00 app[web.1]:
2020-01-20T23:39:51.165784+00:00 app[web.1]:
2020-01-20T23:39:51.165819+00:00 app[web.1]: > jackpot@1.0.0 client-install /app
2020-01-20T23:39:51.165823+00:00 app[web.1]: > npm install --prefix client
2020-01-20T23:39:51.165825+00:00 app[web.1]:
2020-01-20T23:40:43.615827+00:00 app[web.1]:
2020-01-20T23:40:43.615852+00:00 app[web.1]: > core-js@2.6.11 postinstall /app/client/node_modules/core-js
2020-01-20T23:40:43.615854+00:00 app[web.1]: > node -e "try{require('./postinstall')}catch(e){}"
2020-01-20T23:40:43.615856+00:00 app[web.1]:
2020-01-20T23:40:43.691296+00:00 app[web.1]: Thank you for using core-js ( https://github.com/zloirock/core-js ) for
polyfilling JavaScript standard library!
2020-01-20T23:40:43.691299+00:00 app[web.1]:
2020-01-20T23:40:43.691302+00:00 app[web.1]: The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
2020-01-20T23:40:43.691305+00:00 app[web.1]: > https://opencollective.com/core-js 
2020-01-20T23:40:43.691307+00:00 app[web.1]: > https://www.patreon.com/zloirock 
2020-01-20T23:40:43.691309+00:00 app[web.1]:
2020-01-20T23:40:43.691311+00:00 app[web.1]: Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
2020-01-20T23:40:43.691313+00:00 app[web.1]:
2020-01-20T23:40:43.705353+00:00 app[web.1]:
2020-01-20T23:40:43.705360+00:00 app[web.1]: > core-js-pure@3.6.4 postinstall /app/client/node_modules/core-js-pure
2020-01-20T23:40:43.705365+00:00 app[web.1]: > node -e "try{require('./postinstall')}catch(e){}"
2020-01-20T23:40:43.705368+00:00 app[web.1]:
2020-01-20T23:40:44.193688+00:00 app[web.1]:
2020-01-20T23:40:44.193702+00:00 app[web.1]: > core-js@3.6.4 postinstall /app/client/node_modules/react-app-polyfill/node_modules/core-js
2020-01-20T23:40:44.193707+00:00 app[web.1]: > node -e "try{require('./postinstall')}catch(e){}"
2020-01-20T23:40:44.193709+00:00 app[web.1]:
2020-01-20T23:40:47.195666+00:00 heroku[web.1]: State changed from starting to crashed
2020-01-20T23:40:47.199923+00:00 heroku[web.1]: State changed from crashed to starting
2020-01-20T23:40:47.087841+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-01-20T23:40:47.088001+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-01-20T23:40:47.175500+00:00 heroku[web.1]: Process exited with status 137

我在线进行了一些研究,发现它与以下几行有关: server.js

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


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

唯一的问题是我让客户端代码对服务器执行API调用,这需要我使用代理。

server.js

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

const users = require("./routes/api/users");

const app = express();

// Bodyparser 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,
    { useNewUrlParser: true,
      useUnifiedTopology: true
     }
  )
  .then(() => console.log("MongoDB successfully connected"))
  .catch(err => console.log(err));

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

// Passport config
require("./config/passport")(passport);

// Routes
app.use("/api/users", users);

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


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

服务器package.json

    {
  "name": "jackpot",
  "version": "1.0.0",
  "description": "JackPot Application",
  "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\"",
    "prod": "NODE_ENV=production concurrently \"npm run server\" \"npm run client\""
  },
  "author": "",
  "license": "MIT",
  "dependencies": {
    "axios": "^0.19.1",
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.18.3",
    "concurrently": "^4.0.1",
    "express": "^4.16.4",
    "fs": "0.0.1-security",
    "is-empty": "^1.2.0",
    "jquery": "^3.4.1",
    "jsonwebtoken": "^8.3.0",
    "mongoose": "^5.3.11",
    "nodemailer": "^6.4.2",
    "particles-bg": "^2.4.7",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "readline": "^1.3.0",
    "sweetalert2": "^9.5.4",
    "validator": "^10.9.0",
    "ws": "^7.2.1"
  }
}

/client/package.json

    {
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.19.1",
    "classnames": "^2.2.6",
    "jquery": "^3.4.1",
    "jwt-decode": "^2.2.0",
    "particles-bg": "^2.4.7",
    "react": "^16.6.3",
    "react-chat-window": "^1.2.1",
    "react-dom": "^16.6.3",
    "react-redux": "^7.1.3",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.2.0",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:5000",
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

我希望你们中的一个能帮助我,我已经挠头了几个小时。

0 个答案:

没有答案