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 futurestudio / hapi-dev-errors / test / plugin-is-disabled-in-production.js View on Github external
'use strict'

const Lab = require('@hapi/lab')
const Code = require('@hapi/code')
const Hapi = require('@hapi/hapi')

const server = new Hapi.Server()

const { experiment, test, before } = (exports.lab = Lab.script())

experiment('hapi-dev-error register plugin', () => {
  before(async () => {
    // fake production env
    process.env.NODE_ENV = 'production'

    await server.register({
      plugin: require('../lib/index'),
      options: {
        showErrors: process.env.NODE_ENV !== 'production'
      }
    })
  })
github dwyl / hapi-auth-jwt2 / test / error_func_server.js View on Github external
const Hapi   = require('@hapi/hapi');
const secret = 'NeverShareYourSecret';

// for debug options see: http://hapijs.com/tutorials/logging
let debug;
// debug = { debug: { 'request': ['error', 'uncaught'] } };
debug = { debug: false };
const server = new Hapi.Server(debug);

const sendToken = function(req, reply) {
  return req.auth.token || null;
};

const privado = function(req, reply) {
  return req.auth.credentials;
};

// defining our own validate function lets us do something
// useful/custom with the decodedToken before reply(ing)
const customVerify = function (decoded, request) {
  if(decoded.error) {
    throw new Error('customVerify fails!');
  }
  else if (decoded.custom_error) {
github Algram / ytdl-webserver / src / server / server.js View on Github external
const Hapi = require('@hapi/hapi')
const Inert = require('@hapi/inert')
const mkdirp = require('mkdirp')
const path = require('path')
const youtube = require('./handlers/youtube')

const server = new Hapi.Server({
  port: process.env.PORT || 3000,
  routes: {
    files: {
      relativeTo: path.join(__dirname, '../../public')
    }
  }
})

const provision = async () => {
  await server.register(Inert)

  // TODO add notifications to app
  // TODO remove duplicate downloads from ui
  server.route({
    method: 'GET',
    path: '/{path*}',
github rse / graphql-tutorial / sample-13.js View on Github external
;(async () => {
    /*  setup network service  */
    let server = new HAPI.Server({
        address:  "0.0.0.0",
        port:     12345
    })

    /*  establish the HAPI route for GraphiQL UI  */
    await server.register({
        plugin: HAPIGraphiQL,
        options: {
            graphiqlURL:      "/api",
            graphqlFetchURL:  "/api",
            graphqlFetchOpts: `{
                method: "POST",
                headers: {
                    "Content-Type": "application/json",
                    "Accept":       "application/json"
                },
github valtlfelipe / hapi-sequelizejs / test / index.js View on Github external
test('should get DB instance on request', async () => {
        const server = new Hapi.Server();

        await server.register([
            {
                plugin: require('../lib/'),
                options: [
                    {
                        name: 'test',
                        models: [Path.join(__dirname, '/models/**/*.js')],
                        sync: true,
                        sequelize: new Sequelize('test', null, null, {
                            logging: false,
                            dialect: 'sqlite',
                            storage: Path.join(__dirname, 'db.sqlite'),
                        }),
                    },
                ],
github antonsamper / hapi-cron / __tests__ / index.js View on Github external
it('should expose access to the registered jobs', async () => {

        const server = new Hapi.Server();

        await server.register({
            plugin: HapiCron,
            options: {
                jobs: [{
                    name: 'testcron',
                    time: '*/10 * * * * *',
                    timezone: 'Europe/London',
                    request: {
                        method: 'GET',
                        url: '/test-url'
                    }
                }]
            }
        });
github hapijs / vision / examples / mustache / layout.js View on Github external
internals.main = async function () {

    const server = Hapi.Server({ port: 3000 });

    await server.register(Vision);

    server.views({
        engines: {
            html: {
                compile: function (template) {

                    Mustache.parse(template);

                    return function (context) {

                        return Mustache.render(template, context);
                    };
                }
            }
github BlackBoxVision / typescript-hapi-starter / src / server.ts View on Github external
public static async start(): Promise {
    try {
      DotEnv.config({
        path: `${process.cwd()}/.env`,
      });

      Server._instance = new Hapi.Server({
        port: process.env.PORT,
      });

      await Plugin.registerAll(Server._instance);
      await Router.loadRoutes(Server._instance);

      await Server._instance.start();

      Logger.info(
        `Server - Up and running at http://${process.env.HOST}:${process.env.PORT}`
      );
      Logger.info(
        `Server - Visit http://${process.env.HOST}:${process.env.PORT}/api/users for REST API`
      );
      Logger.info(
        `Server - Visit http://${process.env.HOST}:${process.env.PORT}/documentation for Swagger docs`
github ccarruitero / makemehapi / exercises / proxies / solution / solution.js View on Github external
(async () => {
  try {
    const server = Hapi.Server({
      host: 'localhost',
      port: process.argv[2] || 8080
    });

    await server.register(H2o2);

    server.route({
      method: 'GET',
      path: '/proxy',
      handler: {
        proxy: {
          host: '127.0.0.1',
          port: 65535
        }
      }
    });
github ccarruitero / makemehapi / exercises / views / solution / solution.js View on Github external
(async () => {
  try {
    const serverPort = process.argv[2] || 8080;
    const server = Hapi.Server({
      host: 'localhost',
      port: serverPort
    });

    await server.register(Vision);

    server.views({
      engines: {
        html: Handlebars
      },
      path: Path.join(__dirname, 'templates')
    });

    server.route({
      path: '/',
      method: 'GET',

@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