Loopbackjs 环回4 REST控制器路径返回NotFoundError 404
使用通过CLI创建具有CRUD函数对象的REST控制器Loopbackjs 环回4 REST控制器路径返回NotFoundError 404,loopbackjs,Loopbackjs,使用通过CLI创建具有CRUD函数对象的REST控制器 lb4控制器媒体 指向现有实体媒体模型的现有媒体存储库 它们都是使用lb4 CLI生成的 已使用/media的所有REST路由创建MediaController类* /ping路由工作得很好,所以我为它寻找了任何特殊的路由配置,看看是否有/media的配置混乱,但没有什么明显的 具有以下内容的网页的HTTP Get请求/媒体响应: <h1>NotFoundError</h1> <h2><em
lb4控制器媒体
指向现有实体媒体模型的现有媒体存储库
它们都是使用lb4 CLI生成的
已使用/media的所有REST路由创建MediaController类*
/ping路由工作得很好,所以我为它寻找了任何特殊的路由配置,看看是否有/media的配置混乱,但没有什么明显的
具有以下内容的网页的HTTP Get请求/媒体响应:
<h1>NotFoundError</h1>
<h2><em>404</em> Endpoint "GET /media" not found.</h2>
NotFoundError
404终点和34;GET/media";没有找到。
可能需要进行一些基本的配置或设置,但我没有看到
MediaController类
import {
Count,
CountSchema,
Filter,
repository,
Where,
} from '@loopback/repository';
import {
post,
param,
get,
getFilterSchemaFor,
getWhereSchemaFor,
patch,
put,
del,
requestBody, Request, RestBindings, ResponseObject
} from '@loopback/rest';
import { Media } from '../models';
import { MediaRepository } from '../repositories';
export class MediaController {
constructor(
@repository(MediaRepository)
public mediaRepository: MediaRepository,
) { }
@post('/media', {
responses: {
'200': {
description: 'Media model instance',
content: { 'application/json': { schema: { 'x-ts-type': Media } } },
},
},
})
async create(@requestBody() media: Media): Promise<Media> {
return await this.mediaRepository.create(media);
}
@get('/media/count', {
responses: {
'200': {
description: 'Media model count',
content: { 'application/json': { schema: CountSchema } },
},
},
})
async count(
@param.query.object('where', getWhereSchemaFor(Media)) where?: Where<Media>,
): Promise<Count> {
return await this.mediaRepository.count();
}
@get('/media', {
responses: {
'200': {
description: 'Array of Media model instances',
content: {
'application/json': {
schema: { type: 'array', items: { 'x-ts-type': Media } },
},
},
},
},
})
async find(
@param.query.object('filter', getFilterSchemaFor(Media)) filter?: Filter<Media>,
): Promise<Media[]> {
return await this.mediaRepository.find(filter);
}
@patch('/media', {
responses: {
'200': {
description: 'Media PATCH success count',
content: { 'application/json': { schema: CountSchema } },
},
},
})
async updateAll(
@requestBody() media: Media,
@param.query.object('where', getWhereSchemaFor(Media)) where?: Where<Media>,
): Promise<Count> {
return await this.mediaRepository.updateAll(media, where);
}
@get('/media/{id}', {
responses: {
'200': {
description: 'Media model instance',
content: { 'application/json': { schema: { 'x-ts-type': Media } } },
},
},
})
async findById(@param.path.string('id') id: string): Promise<Media> {
return await this.mediaRepository.findById(id);
}
@patch('/media/{id}', {
responses: {
'204': {
description: 'Media PATCH success',
},
},
})
async updateById(
@param.path.string('id') id: string,
@requestBody() media: Media,
): Promise<void> {
await this.mediaRepository.updateById(id, media);
}
@put('/media/{id}', {
responses: {
'204': {
description: 'Media PUT success',
},
},
})
async replaceById(
@param.path.string('id') id: string,
@requestBody() media: Media,
): Promise<void> {
await this.mediaRepository.replaceById(id, media);
}
@del('/media/{id}', {
responses: {
'204': {
description: 'Media DELETE success',
},
},
})
async deleteById(@param.path.string('id') id: string): Promise<void> {
await this.mediaRepository.deleteById(id);
}
}
导入{
计数
CountSchema,
滤器
存储库,
哪里
}来自“@loopback/repository”;
进口{
邮递
param,
收到
getFilterSchemaFor,
GetWhere SchemaFor,
色斑
放
德尔,
requestBody、Request、RestBindings、ResponseObject
}来自“@loopback/rest”;
从“../models”导入{Media};
从“../repositories”导入{MediaRepository};
导出类MediaController{
建造师(
@存储库(MediaRepository)
公共媒体存储库:媒体存储库,
) { }
@post(“/media”{
答复:{
'200': {
描述:'媒体模型实例',
内容:{'application/json':{schema:{'x-ts-type':媒体},
},
},
})
异步创建(@requestBody()媒体:媒体):承诺{
返回等待this.mediaRepository.create(媒体);
}
@获取(“/media/count”{
答复:{
'200': {
描述:“媒体型号计数”,
内容:{'application/json':{schema:CountSchema}},
},
},
})
异步计数(
@param.query.object('where',getWhereSchemaFor(Media))where?:where,
):承诺{
return wait this.mediaRepository.count();
}
@获取(“/media”{
答复:{
'200': {
描述:“媒体模型实例数组”,
内容:{
“应用程序/json”:{
架构:{type:'array',项:{'x-ts-type':媒体},
},
},
},
},
})
异步查找(
@param.query.object('filter',getFilterSchemaFor(Media))filter?:filter,
):承诺{
return wait this.mediaRepository.find(filter);
}
@修补程序(“/media”{
答复:{
'200': {
描述:“媒体修补程序成功计数”,
内容:{'application/json':{schema:CountSchema}},
},
},
})
异步更新(
@requestBody()媒体:媒体,
@param.query.object('where',getWhereSchemaFor(Media))where?:where,
):承诺{
return wait this.mediaRepository.updateAll(media,where);
}
@获取('/media/{id}'{
答复:{
'200': {
描述:'媒体模型实例',
内容:{'application/json':{schema:{'x-ts-type':媒体},
},
},
})
异步findById(@param.path.string('id')id:string):承诺{
返回wait this.mediaRepository.findById(id);
}
@修补程序('/media/{id}'{
答复:{
'204': {
描述:“媒体修补程序成功”,
},
},
})
异步updateById(
@param.path.string('id')id:string,
@requestBody()媒体:媒体,
):承诺{
等待这个.mediaRepository.updateById(id,media);
}
@put('/media/{id}'{
答复:{
'204': {
描述:“媒体投放成功”,
},
},
})
异步替换字节ID(
@param.path.string('id')id:string,
@requestBody()媒体:媒体,
):承诺{
等待这个.mediaRepository.replaceById(id,media);
}
@del('/media/{id}'{
答复:{
'204': {
描述:“媒体删除成功”,
},
},
})
异步deleteById(@param.path.string('id')id:string):承诺{
等待这个.mediaRepository.deleteById(id);
}
}
所以我将lb4放在一边一段时间,同时评估其他框架
今天回到我的lb4演示项目。从那以后,一切都没有改变。启动应用程序
npm run start
浏览到本地主机:3000/媒体
令我惊讶的是,它返回了一个json响应。现在我的响应数组是空的,它应该返回一些东西,因为mongodb数据源中有文档,但这是一个单独的问题。你能分享你的MediaController.ts代码吗?哈哈。。。无论如何