本文整理汇总了TypeScript中hapi.Server.dependency方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Server.dependency方法的具体用法?TypeScript Server.dependency怎么用?TypeScript Server.dependency使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hapi.Server
的用法示例。
在下文中一共展示了Server.dependency方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: DocumentListsController
exports.register = (server: Server, options: any, next: Function) => {
const controller = new DocumentListsController();
server.dependency("hapi-mongodb", (server: Server, next: Function) => {
controller.useDb(server.plugins["hapi-mongodb"].db);
return next();
});
server.route({
method: "GET",
path: "/docList",
config: {
description: "Get the list of documents",
tags: ["api"],
pre: [
{ method: controller.getDocList, assign: "docList" },
{ method: controller.getSerialisedDocList, assign: "serialisedDocList" }
],
handler: controller.sendDocList
}
});
return next();
};
示例2: RecordsController
exports.register = (server: Server, options: any, next: Function) => {
const controller = new RecordsController();
server.dependency("hapi-mongodb", (server: Server, next: Function) => {
controller.useDb(server.plugins["hapi-mongodb"].db);
return next();
});
server.route({
path: "/docs/{slug}/subdocs/{subdocId}/records/{recordId}",
method: "GET",
config: {
description: "Get a record",
notes: "Returns a record by the slug and subdocument id passed in the path",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 3
}
},
validate: {
params: {
slug: Joi.string()
.required()
.description("the slug for the document"),
subdocId: Joi.number()
.required()
.description("the id for the subdocument"),
recordId: Joi.number()
.required()
.description("the id for the record"),
}
},
pre: [
{ method: controller.getRecord, assign: "record" },
{ method: controller.getSerializedRecord, assign: "serialisedRecord" }
],
handler: controller.sendRecord
}
});
return next();
};
示例3: DocumentsController
exports.register = (server: Server, options: any, next: Function) => {
const controller = new DocumentsController();
server.dependency("hapi-mongodb", (server: Server, next: Function) => {
controller.useDb(server.plugins["hapi-mongodb"].db);
return next();
});
server.route({
method: "GET",
path: "/docs/{slug}",
config: {
description: "Get a document",
notes: "Returns a document by the slug passed in the path",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 1
}
},
validate: {
params: {
slug: Joi.string()
.required()
.description("the slug for the document"),
}
},
pre: [
{ method: controller.getDocument, assign: "document" },
{ method: controller.getSerializedDocument, assign: "serializedDocument" }
],
handler: controller.sendDocument
}
});
return next();
};
示例4: SuffixesController
exports.register = (server: Server, options: any, next: Function) => {
const controller = new SuffixesController();
server.dependency("hapi-mongodb", (server: Server, next: Function) => {
controller.useDb(server.plugins["hapi-mongodb"].db);
return next();
});
server.route({
method: "GET",
path: "/suffixes",
config: {
description: "Get all suffixes",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 1
}
},
pre: [
{ method: controller.getSuffixes, assign: "suffixes" },
{ method: controller.getSerializedSuffixes, assign: "serializedSuffixes" }
],
handler: controller.sendSuffixes
}
});
server.route({
method: "GET",
path: "/suffixes/{id}",
config: {
description: "Get a suffix",
notes: "Returns a suffix for the given id",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 2
}
},
validate: {
params: {
id: Joi.string().required()
.description("the id for the suffix")
}
},
pre: [
{
method: controller.getSuffix,
assign: "suffix"
},
{
method: controller.getSerializedSuffix,
assign: "serializedSuffix"
}
],
handler: controller.sendSuffix
}
});
server.route({
method: "GET",
path: "/suffixes/search",
config: {
description: "Search for a suffix",
notes: "Returns all suffixes matching given criterion",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 3
}
},
validate: {
query: {
startsWith: Joi.string().required()
.description("the first few characters of the suffix")
}
},
pre: [
{
method: controller.getMatchingSuffixes,
assign: "suffixes"
},
{
method: controller.getSerializedSuffixes,
assign: "serializedSuffixes"
}
],
handler: controller.sendSuffixes
}
});
return next();
};
示例5: PrefixesController
exports.register = (server: Server, options: any, next: Function) => {
const controller = new PrefixesController();
server.dependency("hapi-mongodb", (server: Server, next: Function) => {
controller.useDb(server.plugins["hapi-mongodb"].db);
return next();
});
server.route({
method: "GET",
path: "/prefixes",
config: {
description: "Get all prefixes",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 1
}
},
pre: [
{ method: controller.getPrefixes, assign: "prefixes" },
{ method: controller.getSerializedPrefixes, assign: "serializedPrefixes" }
],
handler: controller.sendPrefixes
}
});
server.route({
method: "POST",
path: "/prefixes",
config: {
description: "Create prefix",
notes: "Returns the newly created prefix",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 1
}
},
validate: {
payload: {
data: Joi.object().required().keys({
type: Joi.string().required().default("prefixes"),
attributes: Joi.object().required().keys({
prefix: Joi.string().required().description("the prefix"),
senses: Joi.array().required().description("senses for controller prefix")
})
})
}
},
pre: [
{ method: controller.getPrefixPayload, assign: "newPrefix" },
{ method: controller.createPrefix, assign: "prefix" },
{ method: controller.getSerializedPrefix, assign: "serializedPrefix" }
],
handler: controller.sendNewPrefix
}
});
server.route({
method: "GET",
path: "/prefixes/{id}",
config: {
description: "Get a prefix",
tags: ["api"],
notes: "Returns a prefix for the given id",
plugins: {
"hapi-swagger": {
order: 2
}
},
validate: {
params: {
id: Joi.string()
.required()
.description("the id for the prefix"),
}
},
pre: [
{ method: controller.getPrefix, assign: "prefix" },
{ method: controller.getSerializedPrefix, assign: "serializedPrefix" }
],
handler: controller.sendPrefix
}
});
server.route({
method: "DELETE",
path: "/prefixes/{id}",
config: {
description: "Delete a prefix",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 2
}
},
//.........这里部分代码省略.........
示例6: RootsController
exports.register = (server: Server, options: any, next: Function) => {
const controller = new RootsController();
server.dependency("hapi-mongodb", (server: Server, next: Function) => {
controller.useDb(server.plugins["hapi-mongodb"].db);
return next();
});
server.route({
method: "GET",
path: "/roots",
config: {
description: "Get all roots",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 1
}
},
pre: [
{ method: controller.getRoots, assign: "roots" },
{ method: controller.getSerializedRoots, assign: "serializedRoots" }
],
handler: controller.sendRoots
}
});
server.route({
method: "GET",
path: "/roots/search",
config: {
description: "Search through roots",
notes: "Returns matching roots beginning with the given characters",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 3
}
},
validate: {
query: {
startsWith: Joi.string()
.required()
.description("the root to search"),
}
},
pre: [
{ method: controller.getMatchingRoots, assign: "roots" },
{ method: controller.getSerializedRoots, assign: "serializedRoots" }
],
handler: controller.sendRoots
}
});
server.route({
method: "GET",
path: "/roots/{id}",
config: {
description: "Get a root",
notes: "Returns a root for the given id",
tags: ["api"],
plugins: {
"hapi-swagger": {
order: 2
}
},
validate: {
params: {
id: Joi.string()
.required()
.description("the id for the root"),
}
},
pre: [
{ method: controller.getRoot, assign: "root" },
{ method: controller.getSerializedRoot, assign: "serializedRoot" }
],
handler: controller.sendRoot
}
});
return next();
};