i have been struggling with Loopback4 for days...Lb3 was so much easier...
my goal is to authenticate all of my routes except @get route.
configuration went well and when i tried to get route i got a message that route is authenticated, so i have put authenticate.skip(), and then got 500 status code:
ResolutionError: The key 'dataSources.mongoDS' is not bound to any value in context
It's probably a simple solution but i cannot find it...
my code is:
i have imported components in application.ts
this.component(AuthenticationComponent)
this.component(JWTAuthenticationComponent)
this.dataSource(MongoDsDataSource, UserServiceBindings.DATASOURCE_NAME)
this.bind(UserServiceBindings.USER_SERVICE).toClass(MyUserService);
this is my datasource code:
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);
}
}
and this is my repository code:
export class RopeRepository extends DefaultCrudRepository<
Rope,
typeof Rope.prototype.id,
RopeRelations
> {
constructor(
@inject('dataSources.mongoDS') dataSource: MongoDsDataSource,
) {
super(Rope, dataSource);
}
}
question from:
https://stackoverflow.com/questions/65889006/loopback4-with-mongodb-authentification-status-code-500-error 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…