Skip to main content

Community Q&A Monthly Digest - Jun 2020

· 3 min read
Diana Lau

Originally published on strongloop.com

Welcome back to the "Community Q&A Monthly Digest", in which we highlight some of the questions and answers in our LoopBack Slack community here.

Question: Has anyone implemented Casbin on a brand new project? or is there a good tutorial for lb4? I need to have some rbac / roles system in an app.. or what would you suggest to achieve that?

Answer: We have an access control example uses casbin, see the access-control-migration example and its tutorial. The logic on casbin side is only a prototype, the example mainly shows the integration between casbin and LoopBack authorization system.


Question: I am new to LoopBack and so far I really like what it has to offer. I was wondering if anyone knows of a good online course to learn LoopBack. I have worked through the basic tutorials found in the documentation, but I find it easier to listen and follow along to videos.

Answer: Recently one of our community member posts a YouTube tutorial for LoopBack 4 beginners. There is another series of educational videos on a LoopBack introduction and installation.

From our side, there are a few recent videos on our StrongLoop YouTube channel and we're trying to add more. Hope it helps.


Question: I am trying to disable the openapi.json from showing in my loopback 4 application and its not working. I was able to disable the explorer. Any ideas?

Answer: You can use openApiSpec: {disabled: true} in index.ts. i.e.

const config = {
rest: {
//..
openApiSpec: {
disabled: true
//..
},
},
};

Question: Does Loopback 4 support extracting cookies from the header? Currently I had to integrate Express server to achieve this.

Answer: You can use express middleware like http://expressjs.com/en/resources/middleware/cookie-parser.html see how to use middleware in https://loopback.io/doc/en/lb4/Express-middleware.html.


Question: Is there a quick way to generate timestamp? Like at the model level generated:true?

Answer: I recommend to use defaultFn set to one of the following string values:

  • "guid": generate a new globally unique identifier (GUID) using the computer MAC address and current time (UUID version 1).
  • "uuid": generate a new universally unique identifier (UUID) using the computer MAC address and current time (UUID version 1).
  • "uuidv4": generate a new universally unique identifier using the UUID version 4 algorithm.
  • "now": use the current date and time as returned by new Date()

See also https://github.com/strongloop/loopback/issues/292 and https://loopback.io/doc/en/lb4/Model.html#property-decorator.

It would be great to capture these options in our TypeScript definitions, see https://github.com/strongloop/loopback-next/blob/ae6427322451c914ae54f44dbb656981e7fbbb81/packages/repository/src/model.ts#L34-L42.


Question: Can I use MongoDB update operators in LoopBack apps? How can I enable it?

Answer: Yes, except comparison and logical operators, the mongo connector also supports MongoDB update operators such as max, rename, etc. You will need to set the flag allowExtendedOperators to true in the datasource configuration. You can find details and examples at MongoDB connector - update operators.


Interested to Join our Slack Workspace?

Simply click this invitation link to join. You can also find more channel details here: https://github.com/strongloop/loopback-next/issues/5048.