當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Server.start方法代碼示例

本文整理匯總了TypeScript中hapi.Server.start方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Server.start方法的具體用法?TypeScript Server.start怎麽用?TypeScript Server.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在hapi.Server的用法示例。


在下文中一共展示了Server.start方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

        it('creates a healthcheck endpoint', async () => {
          server = new ApolloServer({
            typeDefs,
            resolvers,
          });
          app = new Server({ port });

          await server.applyMiddleware({ app });
          await app.start();

          httpServer = app.listener;
          const { port: appPort } = app.info;

          return new Promise((resolve, reject) => {
            request(
              {
                url: `http://localhost:${appPort}/.well-known/apollo/server-health`,
                method: 'GET',
              },
              (error, response, body) => {
                if (error) {
                  reject(error);
                } else {
                  expect(body).toEqual(JSON.stringify({ status: 'pass' }));
                  expect(response.statusCode).toEqual(200);
                  resolve();
                }
              },
            );
          });
        });
開發者ID:apollostack,項目名稱:apollo-server,代碼行數:31,代碼來源:ApolloServer.test.ts

示例2:

server.register(Nes).then(() => {

    return server.start().then(() => {

        server.broadcast('welcome!');
    });
});
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:7,代碼來源:broadcast-server.ts

示例3: start

  public async start(options: Readonly<BasePathProxyServerOptions>) {
    this.log.debug('starting basepath proxy server');

    const serverOptions = getServerOptions(this.httpConfig);
    this.server = createServer(serverOptions);

    // Register hapi plugin that adds proxying functionality. It can be configured
    // through the route configuration object (see { handler: { proxy: ... } }).
    await this.server.register({ plugin: require('h2o2') });

    if (this.httpConfig.ssl.enabled) {
      const tlsOptions = serverOptions.tls as TlsOptions;
      this.httpsAgent = new HttpsAgent({
        ca: tlsOptions.ca,
        cert: tlsOptions.cert,
        key: tlsOptions.key,
        passphrase: tlsOptions.passphrase,
        rejectUnauthorized: false,
      });
    }

    this.setupRoutes(options);

    await this.server.start();

    this.log.info(
      `basepath proxy server running at ${this.server.info.uri}${this.httpConfig.basePath}`
    );
  }
開發者ID:austec-automation,項目名稱:kibana,代碼行數:29,代碼來源:base_path_proxy_server.ts

示例4: createApp

async function createApp(options: CreateAppOptions) {
  const server = new hapi.Server({
    host: 'localhost',
    port: 8000,
  });

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

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

  await server.start();

  return server.listener;
}
開發者ID:chentsulin,項目名稱:apollo-server,代碼行數:28,代碼來源:hapiApollo.test.ts

示例5: async

const start = async () => {
    await server.register(AuthBearer);

    server.auth.strategy('simple', 'bearer-access-token', {
        allowQueryToken: true,              // optional, false by default
        validate: (async (request, token, h) => {
            // here is where you validate your token
            // comparing with token from your database for example
            const isValid = token === '1234';

            const credentials = { token };
            const artifacts = { test: 'info' };

            return { isValid, credentials, artifacts };
        }) as AuthBearer.Validate
    });

    server.auth.default('simple');

    server.route({
        method: 'GET',
        path: '/',
        handler: async (request, h) => {
            return { info: 'success!' };
        }
    });

    await server.start();

    return server;
};
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:hapi-auth-bearer-token-tests.ts

示例6: 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

示例7: startHapi

export async function startHapi(graphqlOptions) {
  const server = new hapi.Server({
      host: 'localhost',
      port: hapiPort,
  })

  await server.register({
      options: {
          graphqlOptions,
          path: '/graphql',
      },
      plugin: apollo.graphqlHapi,
  })

  await server.register({
      options: {
          graphiqlOptions: {
              endpointURL: '/graphql',
          },
          path: '/',
      },
      plugin: apollo.graphiqlHapi,
  })

  await server.start()
  console.log(`HAPI server is listen on ${hapiPort}`)
  console.log(`open browser to http://localhost:${hapiPort}`)
}
開發者ID:nnance,項目名稱:swapi-apollo,代碼行數:28,代碼來源:hapi.ts

示例8: startServer

async function startServer() {
    // Create a server with a host and port
    const options = {
        host: 'localhost',
        port: 3000,
    }

    const server = new Server(options)

    await server.register({
        options: {
            graphqlOptions: { schema },
            path: '/graphql',
        },
        plugin: graphqlHapi,
    })

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

    try {
        await server.start()
        console.log(`Server is listen on ${options.port}`)
        console.log(`open browser to http://localhost:${options.port}`)
    } catch (e) {
        console.error(e)
    }
}
開發者ID:nnance,項目名稱:express-hapi-graphql,代碼行數:35,代碼來源:hapi.ts

示例9:

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

    await server.register(Schwifty);
    await server.register({
        plugin: Schwifty.plugin,
        options: {
            knex: {
                client: "sqlite3",
                useNullAsDefault: true,
                connection: {
                    filename: ":memory:"
                }
            }
        }
    });

    Schwifty.assertCompatible(DogModel, DogModel);
    // Register a model with schwifty...

    server.schwifty(DogModel);

    await server.initialize();
    const Dog: typeof DogModel = server.models().Dog;

    await Dog.query().insert({ name: "Guinness" });

    // ... then start the server!

    await server.start();

    console.log(`Now, go find some dogs at ${server.info.uri}!`);
})();
開發者ID:Jeremy-F,項目名稱:DefinitelyTyped,代碼行數:33,代碼來源:schwifty-tests.ts


注:本文中的hapi.Server.start方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。