本文整理汇总了TypeScript中@hapi/hapi.Server.inject方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Server.inject方法的具体用法?TypeScript Server.inject怎么用?TypeScript Server.inject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@hapi/hapi.Server
的用法示例。
在下文中一共展示了Server.inject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Server
const server = new Server({
port: 8000,
});
const serverRoute: ServerRoute = {
path: '/',
method: 'GET',
handler(request, h) {
return 'Success!';
}
};
server.route(serverRoute);
server.start();
server.inject('/').then(res => console.log(res.result));
declare module '@hapi/hapi' {
interface ApplicationState {
injectState?: number;
}
}
server.inject({
auth: {
strategy: 'test',
credentials: {
user: {
a: 1,
},
},
示例2: async
const sendRequest = async ({
url,
method = "GET",
}: {
url: string;
method?: string;
}): Promise<Hapi.ServerInjectResponse> => {
const server = new Hapi.Server({ debug: { request: ["*"] } });
await server.register({ plugin });
server.route({
method: "GET",
path: "/",
handler: () => [],
});
// @ts-ignore
server.route({
method: "GET",
path: "/query",
handler: () => [],
options: {
plugins: {
jsonapi: {
validate: {
query: schema,
},
},
},
},
});
// @ts-ignore
server.route({
method: "POST",
path: "/payload",
handler: () => [],
options: {
plugins: {
jsonapi: {
validate: {
payload: schema,
},
},
},
},
});
// @ts-ignore
server.route({
method: "GET",
path: "/params",
handler: () => [],
options: {
plugins: {
jsonapi: {
validate: {
params: schema,
},
},
},
},
});
// @ts-ignore
server.route({
method: "GET",
path: "/headers",
handler: () => [],
options: {
plugins: {
jsonapi: {
validate: {
headers: schema,
},
},
},
},
});
return server.inject({ method, url, payload: {}, headers: { "Content-Type": "application/vnd.api+json" } });
};