cancel
Showing results for 
Search instead for 
Did you mean: 

Add basic express middleware to CAP Applicatoin (CDS)

0 Kudos
39,197

Hey guys! So basically I have my cat-service.cds file which looks like this

---cat-service.cds---
service CatalogService @(requires: 'authenticated-user'){
   entity Books as projection on mydb.BOOKS
   entity Movies as projection on mydb.MOOVIES
}

---cat-service.js---
module.exports = cds.service.impl(srv => {
   srv.on("CREATE", "Books", async(req) => {
  }
}<br>

It works perfectly fine like this, but right now I'm trying to add just a simple express middleware. (for the @sap/logging library to register a logger )

Technically I should have access at srv.use inside the cds.service.impl, but apparently I don't

Does anyone have any idea on how I can register it?

View Entire Topic
dhem
Advisor
Advisor
0 Kudos

Hi Catalin,

if you look at the usage of cds.serve as described here, you will notice that an express app is manually instantiated here. This should give you the possibility to register anything on the app that you like.

Hope that helps!

Best regards,
Dennis

0 Kudos

Yes. I've read the entire doc, but for some reason, I cannot access srv.use. It is undefined

dhem
Advisor
Advisor
0 Kudos

But you don't want to register stuff on the srv, don't you? You want to register it on the app? Basically like this:

const app = require('express')();

//register middleware
app.use(somethingSomethingMiddleware) //cds serve
cds.serve("BookService") ... .in(app) .with(srv => { srv.on("CREATE", "Books", async(req) => { ... } })