本文整理汇总了TypeScript中hapi.Server.register方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Server.register方法的具体用法?TypeScript Server.register怎么用?TypeScript Server.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hapi.Server
的用法示例。
在下文中一共展示了Server.register方法的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;
}
示例2: 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)
}
}
示例3:
(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}!`);
})();
示例4: 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}`)
}
示例5: 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;
}
示例6: 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;
}
示例7: boot
async function boot() {
const server = new Server();
await server.register({
plugin: yar,
options: {
cookieOptions: {
password: 'test',
isSecure: true,
},
cache: {
cache: 'test',
expiresIn: 123141243,
}
},
});
server.route({
path: '/test',
method: 'get',
handler(request: Request) {
const example = request.yar.get('example');
return {
id: request.yar.id,
key: example.key,
};
},
});
}
示例8: 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;
};
示例9: 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}`
);
}
示例10: all
all(plugins.map((plugin) => {
server.register(plugin.module, plugin.options, (err) => {
if (err) {
return Promise.reject(err);
}
return Promise.resolve();
});
}))