Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

Loopback4 with Mongodb authentification status code 500 error

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...