Loopback4与Mongodb认证状态码500错误



我已经与Loopback4斗争了好几天…Lb3就简单多了……我的目标是验证除了@get route之外的所有路由。

配置进行得很顺利,当我试图获得路由时,我得到一条消息,该路由已经过身份验证,因此我放置了authenticate.skip(),然后得到500状态码:

ResolutionError: The key ' datasource。mongoDS'没有绑定到上下文

中的任何值这可能是一个简单的解决方案,但我找不到它。

我的代码是:

我在application.ts中导入了组件

this.component(AuthenticationComponent)
this.component(JWTAuthenticationComponent)
this.dataSource(MongoDsDataSource, UserServiceBindings.DATASOURCE_NAME)
this.bind(UserServiceBindings.USER_SERVICE).toClass(MyUserService);

这是我的源代码:

const config = {
name: 'mongoDS',
connector: 'mongodb',
url: '',
host: 'localhost',
port: 27017,
user: '',
password: '',
database: 'ropesdb',
useNewUrlParser: true
};

@lifeCycleObserver('datasource')
export class MongoDsDataSource extends juggler.DataSource
implements LifeCycleObserver {
static dataSourceName = 'mongoDS';
static readonly defaultConfig = config;
constructor(
@inject('dataSources.config.mongoDS', {optional: true})
dsConfig: object = config,
) {
super(dsConfig);
}
}

,这是我的仓库代码:

export class RopeRepository extends DefaultCrudRepository<
Rope,
typeof Rope.prototype.id,
RopeRelations
> {
constructor(
@inject('dataSources.mongoDS') dataSource: MongoDsDataSource,
) {
super(Rope, dataSource);
}
}

我相信LoopBack使用数据源文件名来确定数据源的名称,并将该名称放在上下文中。例如,[name-in-kebab-case].datasource.ts在上下文中就是datasource.NameInCamelCaseMongoDsDataSource是否在mongo-ds.datasource.ts中?

相关内容