Развертывание Heroku: Node Express + React - PullRequest
0 голосов
/ 06 декабря 2018

Я делаю приложение реакции, используя отличную плиту котла cool-реакции-стартер .Я новичок в полной реакции, поэтому шаблон для меня немного продвинут, но пока он отлично работает.

Моя проблема связана с развертыванием на heroku, при каждом развертывании я получаю ошибку порта R10.Я следовал документам heroku по ошибкам R10 здесь , а также пытался прочитать все соответствующие вопросы стека, которые я могу найти.

Я запускаю приложение с командой yarn start из procfile и у меня есть сценарий yarn build для задачи heroku-postbuild.

Любая помощь, указывающая мне правильное направление, будетс благодарностью!

См. логи heroku ниже:

2018-12-06T10:31:18.853806+00:00 heroku[web.1]: Starting process with command `yarn start`
2018-12-06T10:31:22.699978+00:00 app[web.1]: yarn run v1.12.3
2018-12-06T10:31:22.907990+00:00 app[web.1]: $ better-npm-run start
2018-12-06T10:31:23.236361+00:00 app[web.1]: running better-npm-run in /app
2018-12-06T10:31:23.243282+00:00 app[web.1]: Executing script: start
2018-12-06T10:31:23.243286+00:00 app[web.1]: 
2018-12-06T10:31:23.259185+00:00 app[web.1]: to be executed: node . 
2018-12-06T10:31:42.220791+00:00 app[web.1]: (node:42) 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-12-06T10:31:46.256023+00:00 app[web.1]: (node:42) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
2018-12-06T10:32:19.540746+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-12-06T10:32:19.540844+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-12-06T10:32:19.676042+00:00 heroku[web.1]: Process exited with status 137
2018-12-06T10:32:19.706494+00:00 heroku[web.1]: State changed from starting to crashed

Package.json (соответствующие части):

{
  "name": "react-cool-starter",
  "version": "2.8.0",
  "description": "A starter boilerplate for an universal web application with the best development experience and best practices.",
  "main": "index.js",
  "engines": {
    "node": ">=8",
    "npm": ">=5"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/wellyshen/react-cool-starter"
  },
  "keywords": [
    "starter",
    "boilerpate",
    "universal",
    "react",
    "redux",
    "react router v4",
    "express",
    "webpack v4",
    "es6",
    "flow",
    "code splitting",
    "hot reloading",
    "babel",
    "postcss",
    "jest",
    "unit testing",
    "performance optimizing"
  ],
  "author": "WellyShen <hivoid19@gmail.com> (https://github.com/wellyshen)",
  "license": "MIT",
  "homepage": "https://github.com/wellyshen/react-cool-starter",
  "bugs": {
    "url": "https://github.com/wellyshen/react-cool-starter/issues"
  },
  "sideEffects": false,
  "scripts": {
    "dev": "better-npm-run dev",
    "start": "better-npm-run start",
    "build": "yarn clean:build && better-npm-run build",
    "analyze": "yarn clean:build && better-npm-run analyze",
    "lint": "npm-run-all lint:js lint:style",
    "lint:js": "better-npm-run lint:js",
    "lint:style": "better-npm-run lint:style",
    "flow": "better-npm-run flow",
    "flow:stop": "better-npm-run flow:stop",
    "test": "better-npm-run test",
    "test:watch": "yarn test --watch",
    "test:update-snapshot": "yarn test -u",
    "clean": "npm-run-all clean:build clean:test",
    "clean:build": "better-npm-run clean:build",
    "clean:test": "better-npm-run clean:test",
    "coveralls": "yarn clean:test && better-npm-run coveralls",
    "heroku-postbuild": "yarn build"
  },
  "betterScripts": {
    "dev": {
      "command": "nodemon .",
      "env": {
        "NODE_PATH": "./src",
        "NODE_ENV": "development",
        "PORT": 3000
      }
    },
    "start": {
      "command": "node .",
      "env": {
        "NODE_PATH": "./src"
      }
    },
    "build": {
      "command": "webpack --progress --hide-modules --config ./tools/webpack/config.babel.js",
      "env": {
        "NODE_ENV": "production"
      }
    },

Файл конфигурации среды (удалено имя базы данных):

module.exports = {
  host: process.env.NODE_HOST || 'localhost', // Define your host from 'package.json'
  port: process.env.PORT || 5000,
  dburi: process.env.MONGODB_URI || '****',
  app: {
    htmlAttributes: { lang: 'en' },
    title: 'React Cool Starter',
    titleTemplate: 'React Cool Starter - %s',
    meta: [
      {
        name: 'description',
        content: 'The best react universal starter boilerplate in the world.'
      }
    ]
  }
};

Procfile:

web: yarn start

Мои переменные окружения на heroku выглядят следующим образом:

NODE_ENV= production
NODE_PATH= ./src
NPM_CONFIG_PRODUCTION= false

Если я запускаю приложение локально, используя heroku local web, я такжеполучить 404s на всех моих файлах js chunk ...

Спасибо!

РЕДАКТИРОВАТЬ: РЕШЕНО

Глядя на проблему свежим взглядом, мне удалосьчтобы решить проблему самостоятельно - я пропустил часть документов heroku, описывающих привязку хоста к 0.0.0.0.Добавление этого в качестве моей переменной среды NODE_HOST с использованием heroku config:set решило проблему.Я оставлю это для тех, кто может столкнуться с тем же.Спасибо!

...