How to use the @hapi/hapi.server function in @hapi/hapi

To help you get started, we’ve selected a few @hapi/hapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hapijs / bell / examples / facebook.js View on Github external
internals.start = async function () {

    const server = Hapi.server({ host: 'localhost', port: 8000 });
    await server.register(Bell);

    // You'll need to go to https://developers.facebook.com/ and set up a
    // Website application to get started
    // Once you create your app, fill out Settings and set the App Domains
    // Under Settings >> Advanced, set the Valid OAuth redirect URIs to include http:///bell/door
    // and enable Client OAuth Login

    server.auth.strategy('facebook', 'bell', {
        provider: 'facebook',
        password: 'cookie_encryption_password_secure',
        isSecure: false,
        clientId: '',
        clientSecret: '',
        location: server.info.uri
    });
github jbuget / nodejs-clean-architecture-app / lib / frameworks_drivers / webserver / server.js View on Github external
const createServer = async () => {

  // Create a server with a host and port
  const server = Hapi.server({
    port: process.env.PORT || 3000
  });

  // Register vendors plugins
  await server.register([
    require('blipp'),
    require('@hapi/inert'),
    require('@hapi/vision'),
    {
      plugin: require('hapi-swagger'),
      options: {
        info: {
          title: 'Test API Documentation',
          version: Package.version,
        },
      }
github hapijs / bell / test / providers / bitbucket.js View on Github external
it('authenticates with mock', async (flags) => {

        const mock = await Mock.v2(flags);
        const server = Hapi.server({ host: 'localhost', port: 80 });
        await server.register(Bell);

        const custom = Bell.providers.bitbucket();
        Hoek.merge(custom, mock.provider);

        Mock.override('https://api.bitbucket.org/2.0/user', {
            repositories: [{}],
            uuid: '1E9C5160-E436-11E5-9897-4FCB70D5A8C7',
            username: 'steve',
            display_name: 'steve'
        });

        server.auth.strategy('custom', 'bell', {
            password: 'cookie_encryption_password_secure',
            isSecure: false,
            clientId: 'bitbucket',
github hapijs / h2o2 / test / index.js View on Github external
it('binds onResponse to plugin bind', async () => {

        const upstream = Hapi.server();
        await upstream.start();

        const plugin = {
            register: function (server, options) {

                const onResponseWithError = function (err, res, request, h, settings, ttl) {

                    expect(err).to.be.null();
                    return h.response(h.context.c);
                };

                const handler = {
                    proxy: {
                        host: 'localhost',
                        port: upstream.info.port,
                        onResponse: onResponseWithError
github hapijs / h2o2 / test / index.js View on Github external
it('allows passing in an agent through to Wreck', { parallel: false }, async () => {

        const server = Hapi.server();
        await server.register(H2o2);

        const agent = { name: 'myagent' };

        const httpClient = {
            request(method, uri, options, callback) {

                expect(options.agent).to.equal(agent);
                return { statusCode: 200 };
            }
        };
        server.route({ method: 'GET', path: '/agenttest', handler: { proxy: { uri: 'http://localhost', httpClient, agent } } });
        await server.inject({ method: 'GET', url: '/agenttest', headers: {} }, (res) => { });
    });
github felixheck / laabr / examples / simple.js View on Github external
const hapi = require('@hapi/hapi')
const laabr = require('../src')

const server = hapi.server({ port: 3000 })

server.route([
  {
    method: '*',
    path: '/response',
    handler () {
      return 'hello world'
    }
  },
  {
    method: 'GET',
    path: '/error',
    handler () {
      throw new Error('foobar')
    }
  }
github pinojs / hapi-pino / benchmarks / hapi-pure.js View on Github external
async function start () {
  const server = Hapi.server({ port: 3000 })

  server.route({
    method: 'GET',
    path: '/',
    handler: async function (request, h) {
      return 'hello world'
    }
  })

  await server.start()
}
github pinojs / hapi-pino / benchmarks / hapi-pino-merge-hapi-log.js View on Github external
async function start () {
  const server = Hapi.server({ port: 3000 })

  server.route({
    method: 'GET',
    path: '/',
    handler: async function (request, h) {
      return 'hello world'
    }
  })

  await server.register({
    plugin: require('..'),
    options: {
      mergeHapiLogData: true
    }
  })

@hapi/hapi

HTTP Server framework

BSD-3-Clause
Latest version published 2 months ago

Package Health Score

95 / 100
Full package analysis

Popular @hapi/hapi functions