Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
Hapi accessing server from other js file

I'm more or less new to JS in general and am currently trying to figure out how and why I do not have access to a previously defined server attribute.

In another file I attempt to import

const server = require('./..');

points to the right location as far as I can tell, and all other variables set in a similar manner work fine.

I'm assuming this is an issue in the server registration part of things with Hapi.

const init = async () => {
  // Load dependencies
  require('./conf/os.conf')();
  require('./middleware');
  const model = require('./model');
  require('./routes');
  require('./workers');
  const server = module.exports = Hapi.server({
    port: process.env.PORT,
  });
  await server.register([
    require('hapi-async-handler'),
    require('hapi-auth-bearer-token'),
    require('hapi-overriding'),
    require('inert'),
    require('vision'),
    {
      register: require('hapi-swagger'),
      options: {
        documentationPath: `${process.env.API_BASEURL}/documentation`,
        info: {
          title: 'API Documentation',
          version: process.env.API_VERSION,
          contact: {
            name: 'Mason Fraser',
            email: 'myemail@email.com'
          }
        },
        pathPrefixSize: 3,
        basePath: `${process.env.API_BASEURL}/`
      }
    }, {
      register: require('hapi-pagination'),
      options: {
        query: {
          pagination: {
            default: false
          }
        },
        meta: {
          baseUri: process.env.API_BASEURL,
          limit: {
            active: true
          },
          page: {
            active: true
          }
        }
      }
    }
  ]);
  // Trying things.
  exports.plugin = {
    register: (server, options) => {
      server,
      require('hapi-async-handler'),
      require('hapi-auth-bearer-token'),
      require('hapi-overriding'),
      require('inert'),
      require('vision')
    }
  }
  await server.start();
  console.log('Server running on %s', server.info.uri);
};

Any clues on how to fix this?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda