当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Server.connection方法代码示例

本文整理汇总了TypeScript中hapi.Server.connection方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Server.connection方法的具体用法?TypeScript Server.connection怎么用?TypeScript Server.connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hapi.Server的用法示例。


在下文中一共展示了Server.connection方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: createApp

function createApp(createOptions: HapiPluginOptions) {
  const server = new hapi.Server();

  server.connection({
      host: 'localhost',
      port: 8000,
  });

  server.register({
      register: apolloHapi,
      options: {
        apolloOptions: createOptions ? createOptions.apolloOptions : { schema: Schema },
        path: '/graphql',
      },
  });

  server.register({
      register: graphiqlHapi,
      options: {
        path: '/graphiql',
        graphiqlOptions: {
          endpointURL: '/graphql',
        },
      },
  });

  return server.listener;
}
开发者ID:HriBB,项目名称:apollo-server,代码行数:28,代码来源:hapiApollo.test.ts

示例2: createApp

function createApp(options: CreateAppOptions) {
  const server = new hapi.Server();

  server.connection({
      host: 'localhost',
      port: 8000,
  });

  server.register({
      register: graphqlHapi,
      options: {
        graphqlOptions: (options && options.graphqlOptions) || { schema: Schema },
        path: '/graphql',
      },
  });

  server.register({
      register: graphiqlHapi,
      options: {
        path: '/graphiql',
        graphiqlOptions: (options && options.graphiqlOptions) || { endpointURL: '/graphql' },
      },
  });

  return server.listener;
}
开发者ID:convoyinc,项目名称:apollo-server,代码行数:26,代码来源:hapiApollo.test.ts

示例3: init

 public static init(): Hapi.Server {
     const server = new Hapi.Server();
     server.connection({
         port: 10000,
         router: {
             isCaseSensitive: false,
             stripTrailingSlash: true
         },
         routes: {
             timeout: {
                 server: 10000,
                 socket: false
             },
             cors: {
                 credentials: true,
                 origin: ['*'],
                 headers: ['Accept', 'Authorization',
                           'Content-Type', 'If-None-Match',
                           'Access-Control-Allow-Origin',
                           'Accept-Language']
             },
             files: {
                 relativeTo: Path.join(__dirname, '../')
             }
         }
     });
     server.ext('onPreResponse', corsHeaders);
     server.register(Inert, () => {});
     Api.init(server);
     return server;
 }
开发者ID:asiddeen,项目名称:BiB,代码行数:31,代码来源:server.ts

示例4: start

async function start() {
    const server = new Hapi.Server();

    const env = process.env.NODE_ENV || 'development';
    process.env.NODE_ENV = env; //So the plugins load right
    const configFilePath = path.join(__dirname, "config", env + ".json");
    const userConfigFilePath = path.join(__dirname, "config", env + ".user.json");
    nconf
        .file("user_overrides", userConfigFilePath)
        .file("defaults", configFilePath);

    server.connection({
        host: nconf.get('hapi:host'),
        port: nconf.get('hapi:port')
    });

    const appLogger = new AppLogger();
    server.app.logger = await appLogger.initialize(nconf);

    await Plugin.registerAll(server, nconf);
    await Api.loadRoutes(server);

    await server.start();
    if (server.info !== null) {
        server.app.logger.info(`Server running at ${server.info.uri}`);
    }
}
开发者ID:dangelspencer,项目名称:typed-hapi,代码行数:27,代码来源:index.ts

示例5: initialize

  protected initialize() {
    this.engine = new Hapi();

    this.engine.connection({
      host: 'localhost',
      port: 3000
    });
    return this;
  }
开发者ID:gitter-badger,项目名称:ubiquits,代码行数:9,代码来源:hapi.server.ts

示例6: startServer

export default function startServer(done) {
    const server = new Hapi.Server({
        connections: {
            routes: {
                files: {
                    relativeTo: Path.join(__dirname, '..')
                }
            }
        }
    });
    server.connection({ port: 3000, host: 'localhost' });
    server.register(Inert, (err) => {
        if (err) {
            throw err;
        }
        server.route({
            method: 'GET',
            path: '/',
            handler: function (request, reply) {
                reply.file('index.html');
            }
        });
        server.route({
            method: 'GET',
            path: '/scripts/{param*}',
            handler: {
                directory: {
                    path: 'scripts'
                }
            }
        });
        server.route({
            method: 'GET',
            path: '/styles/{param*}',
            handler: {
                directory: {
                    path: 'styles'
                }
            }
        });
        server.route({
            method: 'GET',
            path: '/api/system/current',
            handler: function (request, reply) {
                reply.file('c3.json');
            }
        });
        server.start((err) => {
            if (err) {
                throw err;
            }
            console.log(`Server running at: ${server.info.uri}`);
        });
    });
    done();
}
开发者ID:jugglingthebits,项目名称:C3,代码行数:56,代码来源:server.ts

示例7: function

module.exports = function(ROOT, serverOptions) {

  var {hapiEngine} = require('angular2-hapi-engine');
  var app = new Hapi.Server();
  app.connection(serverOptions);
  app.register([Vision, Inert], (err) => {

    if (err) {
      throw err;
    }

    // rendering engine
    app.views({
      defaultExtension: 'ng2.html',
      engines: {
        'ng2.html': {
          module: new hapiEngine(),
          compileMode: 'async'
        }
      },
      relativeTo: __dirname,
      path: path.join(ROOT, 'examples')
    });

  });

  var routes = require('./routes');
  app.route(routes(ROOT));

  var api = require('./api');
  app.route(api(ROOT));


  // TODO: is this script being used?
  // var graphApi = require('./graph_api');
  // app.use('/graph_api', api(ROOT));

  // TODO: what route is this?
  // app.use(serveStatic(`${ROOT}/dist`));

  // TODO: figure out how to use morgan with Hapi
  // app.use(morgan('dev'));


  return app;
};
开发者ID:BizagiStudio,项目名称:universal,代码行数:46,代码来源:server.ts

示例8:

SwaggerHapi.create(config, (err, swaggerHapi) => {
  if (err) { throw err; }

  const port = process.env.PORT || 10010;
  app.connection({ port });
  // app.address = function() {
  //   return { port };
  // };

  if (swaggerHapi.config.swagger !== undefined) {
    const appRootFromMw = swaggerHapi.config.swagger.appRoot;
  }

  app.register(swaggerHapi.plugin, err => {
    if (err) { return console.error("Failed to load plugin:", err); }
    // stat app etc..
  });
});
开发者ID:Crevil,项目名称:DefinitelyTyped,代码行数:18,代码来源:swagger-hapi-tests.ts

示例9: resolve

    return new Promise<Hapi.Server>(resolve => {

        const port = process.env.PORT || configs.port;
        const server = new Hapi.Server();

        server.connection({
            port: port,
            routes: {
                cors: true
            }
        });

        if (configs.routePrefix) {
            server.realm.modifiers.route.prefix = configs.routePrefix;
        }

        //  Setup Hapi Plugins
        const plugins: Array<string> = configs.plugins;
        const pluginOptions = {
            database: database,
            serverConfigs: configs
        };

        let pluginPromises = [];

        plugins.forEach((pluginName: string) => {
            var plugin: IPlugin = (require("./plugins/" + pluginName)).default();
            console.log(`Register Plugin ${plugin.info().name} v${plugin.info().version}`);
            pluginPromises.push(plugin.register(server, pluginOptions));
        });

        Promise.all(pluginPromises).then(() => {
            console.log('All plugins registered successfully.');

            console.log('Register Routes');
            Tasks.init(server, configs, database);
            Users.init(server, configs, database);
            console.log('Routes registered sucessfully.');

            resolve(server);
        });
    });
开发者ID:mlinuxgada,项目名称:hapi-typescript-example,代码行数:42,代码来源:server.ts

示例10:

SwaggerNodeRunner.create(config, (err, runner) => {
  if (err) { throw err; }

  var port = process.env.PORT || 10010;
  hapiapp.connection({ port });
//   hapiapp.address = function() {
//     return { port };
//   };
  const hapiMiddleware = runner.hapiMiddleware();

  if (hapiMiddleware.config.swagger !== undefined) {
    const appRootFromMw = hapiMiddleware.config.swagger.appRoot;
  }

  const pluginAttributes = hapiMiddleware.plugin.register.attributes.name + hapiMiddleware.plugin.register.attributes.version;

  hapiapp.register(hapiMiddleware.plugin, err => {
    if (err) { return console.error("Failed to load plugin:", err); }
    // stat app etc..
  });
});
开发者ID:Kroisse,项目名称:DefinitelyTyped,代码行数:21,代码来源:swagger-node-runner-tests.ts


注:本文中的hapi.Server.connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。