本文整理汇总了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();
}
},
);
});
});
示例2:
server.register(Nes).then(() => {
return server.start().then(() => {
server.broadcast('welcome!');
});
});
示例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}`
);
}
示例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;
}
示例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;
};
示例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}`);
}
}
示例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}`)
}
示例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)
}
}
示例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}!`);
})();