Я работаю на сервере Hapi для приложения ReactJS, но когда я пытаюсь установить его в Heroku, я получаю ошибку R10 "Не удалось привязать к $PORT в течение 60 секунд после запуска". Что происходит? Я использую process.env.PORT. Я также попробовал parseInt() вокруг него. Также попытался отключить различные пакеты. Конструкция всегда успешна.
В журналах Heroku я вижу консольный журнал из index.js( "Hapi running on..." ), но затем появляется ошибка R10, и сервер перезапускается, а затем сбой.
== > 🌎 Hapi Production Server (API) прослушивает http://localhost:143162016-01-22T15: 10: 33.947571 + 00: 00 heroku [web.1]: Прекращение процесса с помощью SIGKILL 2016-01-22T15: 10: 33.947571 + 00: 00 heroku [web.1]: ошибка R10 (время ожидания загрузки) → веб-процесс не смог привязываться к $PORT в течение 60 секунд после запуска 2016-01-22T15: 10: 34.737554 + 00: 00 heroku [web.1]: государство изменилось с начала до разбитого 2016-01-22T15: 10: 34.724233 + 00: 00 heroku [web.1]: процесс завершен со статусом 137
Все это выполняется нормально локально, когда я запускаю NODE_ENV = production
ЦСИ/server.js
import Hapi from 'hapi';
import Inert from 'inert';
import jwt from 'hapi-auth-jwt2';
import React from 'react';
import { renderToString } from 'react-dom/server';
import { RoutingContext, match } from 'react-router';
import { Provider } from 'react-redux';
import createRoutes from './routes';
import configureStore from './store/configureStore';
import Html from './Html';
const PROTOCOL = 'http://';
const SERVER_HOST = process.env.HOST || 'localhost';
const SERVER_PORT = process.env.PORT || 3000;
const API_HOST = process.env.API_HOST || 'localhost';
const API_PORT = process.env.API_PORT || 8000;
export default function(callback) {
    const server = new Hapi.Server();
    server.connection({
    host: SERVER_HOST,
    port: SERVER_PORT,
    labels: ['api'],
    // routes: {
    //   cors: {
    //     origin: [PROTOCOL + API_HOST + ':' + API_PORT]
    //   }
    // }
  });
    server.connections[0].name = 'API';
    server.register([
        { register: Inert },
        { register: jwt },
        // {
      //   register: api,
      //   routes: {
      //     prefix: '/api'
      //   }
      // }
    ], (err) => {
    if(err) {
      console.error('ERROR:', err)
      throw err;
    }
        server.route({
        method: 'GET',
        path: '/{param*}',
        handler: {
          directory: {
            path: 'static'
          }
        }
      });
        server.ext('onPreResponse', (request, reply) => {
            if (typeof request.response.statusCode !== 'undefined') {
        return reply.continue();
      }
            const assets = {
                javascript: {
                    main: '/dist/bundle.js'
                }
            };
          const store = configureStore();
          const routes = createRoutes(store);
          // this gets called if server side rendering/routing has problems and errors
          function hydrateOnClient() {
            reply('<!doctype html>\n' +
              renderToString(<Html assets={assets} store={store} />)).code(500);
          }
          match({ routes, location: request.path }, (error, redirectLocation, renderProps) => {
            if (redirectLocation) {
              res.redirect(301, redirectLocation.pathname + redirectLocation.search)
            } else if (error) {
              console.error('ROUTER ERROR:', error) // eslint-disable-line no-console
              hydrateOnClient();
            } else if (!renderProps) {
              // in some cases this would act as a 404 but that should be handled in the routes
              hydrateOnClient();
            } else {
              const component = (
                <Provider store={store}>
                  <RoutingContext {...renderProps} />
                </Provider>
              );
              reply('<!doctype html>\n' +
                renderToString(<Html assets={assets} component={component} store={store} />)
                    );
            }
          });
        });
    });
    return server.start((err) => {
        if(err) {
            console.log(err);
            throw err;
        }
        callback(server)
    });
}
index.js
require('babel-core/register');
global.__DEVELOPMENT__ = process.env.NODE_ENV !== 'production';
global.__SERVER__ = true;
global.__CLIENT__ = false;
const server = require('./src/server');
server(server => {
   for (var key of Object.keys(server.connections)) {
     console.info('==> 🌎 Hapi Production Server (' + server.connections[key].name + ') is listening on', server.connections[key].info.uri);
  }
});
