Приложение Apollo server вылетает на heroku, но работает на localhost - PullRequest
0 голосов
/ 09 июля 2020

При попытке развернуть мой сервер Apollo на heroku происходит сбой (ошибка ниже). Я искал в Google и пробовал то и это, но у меня недостаточно опыта (пока), чтобы понять, что происходит повсюду.

На heroku я установил config var NODE_ENV на production, как описано в Apollo docs.

My config. json:

  "development": {
    "username": "postgres",
    "password": "secret",
    "database": "database_dev",
    "loggin": true,
    "host": "localhost",
    "dialect": "postgres",
    "operatorsAliases": "0"
  },
  "test": {
    "username": "root",
    "password": null,
    "database": "database_test",
    "host": "127.0.0.1",
    "dialect": "postgres",
    "operatorsAliases": "0"
  },
  "production": {
    "use_env_variable": "DATABASE_URL"
  }
}

Сервер:

const server = new ApolloServer({
  typeDefs,
  resolvers,
  context: { models, pubsub },
});

server.listen({ port: process.env.PORT || 4000 }).then(({ url }) => {
  console.log(`? Server ready at ${url}`);
});

Ошибка в журналах Heroku:

2020-07-09T20:20:40.313960+00:00 app[web.1]:     throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
2020-07-09T20:20:40.313961+00:00 app[web.1]:     ^
2020-07-09T20:20:40.313961+00:00 app[web.1]: 
2020-07-09T20:20:40.313962+00:00 app[web.1]: TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined
2020-07-09T20:20:40.313963+00:00 app[web.1]:     at validateString (internal/validators.js:120:11)
2020-07-09T20:20:40.313963+00:00 app[web.1]:     at Url.parse (url.js:159:3)
2020-07-09T20:20:40.313964+00:00 app[web.1]:     at Object.urlParse [as parse] (url.js:154:13)
2020-07-09T20:20:40.313964+00:00 app[web.1]:     at new Sequelize (/app/node_modules/sequelize/lib/sequelize.js:187:28)
2020-07-09T20:20:40.313965+00:00 app[web.1]:     at Object.<anonymous> (/app/models/index.js:13:15)
2020-07-09T20:20:40.313965+00:00 app[web.1]:     at Module._compile (internal/modules/cjs/loader.js:1138:30)
2020-07-09T20:20:40.313966+00:00 app[web.1]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-07-09T20:20:40.313966+00:00 app[web.1]:     at Module.load (internal/modules/cjs/loader.js:986:32)
2020-07-09T20:20:40.313966+00:00 app[web.1]:     at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-07-09T20:20:40.313967+00:00 app[web.1]:     at Module.require (internal/modules/cjs/loader.js:1026:19)
2020-07-09T20:20:40.313967+00:00 app[web.1]:     at require (internal/modules/cjs/helpers.js:72:18)
2020-07-09T20:20:40.313968+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:6:16)
2020-07-09T20:20:40.313968+00:00 app[web.1]:     at Module._compile (internal/modules/cjs/loader.js:1138:30)
2020-07-09T20:20:40.313969+00:00 app[web.1]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2020-07-09T20:20:40.313969+00:00 app[web.1]:     at Module.load (internal/modules/cjs/loader.js:986:32)
2020-07-09T20:20:40.313969+00:00 app[web.1]:     at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2020-07-09T20:20:40.313970+00:00 app[web.1]:     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
2020-07-09T20:20:40.313970+00:00 app[web.1]:     at internal/main/run_main_module.js:17:47 {
2020-07-09T20:20:40.313971+00:00 app[web.1]:   code: 'ERR_INVALID_ARG_TYPE'
2020-07-09T20:20:40.313971+00:00 app[web.1]: }

Также ... Это как-то связано? models / index. js

let sequelize;
if (config.use_env_variable) {
  sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
  sequelize = new Sequelize(
    config.database,
    config.username,
    config.password,
    config
  );
}

Надеюсь, это адекватная информация. Любые идеи? Бесконечное спасибо!

...