From 265cb1453e1222cbd9b5ffebea9391113dd4c945 Mon Sep 17 00:00:00 2001 From: sjvans <30337871+sjvans@users.noreply.github.com> Date: Wed, 29 May 2024 12:18:54 +0200 Subject: [PATCH 01/10] Revert "rm cds.middlewares.after (#952)" This reverts commit 67814eab54a7558f710faad17c461ae2e1a4462b. --- node.js/cds-serve.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node.js/cds-serve.md b/node.js/cds-serve.md index 198ea898e1..f0cb81e650 100644 --- a/node.js/cds-serve.md +++ b/node.js/cds-serve.md @@ -211,7 +211,7 @@ srv/cat-service.js #> service implementation used by default For each service served at a certain protocol, the framework registers a configurable set of express middlewares by default like so: ```js -app.use (cds.middlewares.before, protocol_adapter) +app.use (cds.middlewares.before, protocol_adapter, cds.middlewares.after) ``` The standard set of middlewares uses the following order: From a160e4349fcb24033499087a4d11d82116eb7d06 Mon Sep 17 00:00:00 2001 From: D050513 Date: Wed, 29 May 2024 12:26:08 +0200 Subject: [PATCH 02/10] more details re cds.middlewares.after --- node.js/cds-serve.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/node.js/cds-serve.md b/node.js/cds-serve.md index f0cb81e650..86e2c72adf 100644 --- a/node.js/cds-serve.md +++ b/node.js/cds-serve.md @@ -215,16 +215,27 @@ app.use (cds.middlewares.before, protocol_adapter, cds.middlewares.after) ``` The standard set of middlewares uses the following order: + ```js cds.middlewares.before = [ - context(), // provides cds.context - trace(), // provides detailed trace logs when DEBUG=trace - auth(), // provides req.user & tenant + context(), // provides cds.context + trace(), // provides detailed trace logs when DEBUG=trace + auth(), // provides req.user & tenant ctx_auth(), // propagates auth results to cds.context - ctx_model(), // fills in cds.context.model + ctx_model(), // fills in cds.context.model ] ``` +```js +cds.middlewares.after = [ + cds_error_handler(), // provides final error handling +] +``` + +::: tip +In order for a custom error middleware to be invoked, it must be registered _before_ the built-in `cds_error_handler`. That is, it must be added, for example, via `cds.middlewares.after.unshift()`. +::: + ::: warning _Be aware of the interdependencies of middlewares_ _ctx_model_ requires that _cds.context_ middleware has run before. _ctx_auth_ requires that _authentication_ has run before. From 87782bf7cd970af2c91305231f29d77be08dcb51 Mon Sep 17 00:00:00 2001 From: D050513 Date: Wed, 10 Jul 2024 10:35:52 +0200 Subject: [PATCH 03/10] revert --- node.js/cds-serve.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/node.js/cds-serve.md b/node.js/cds-serve.md index 86e2c72adf..5153e4044e 100644 --- a/node.js/cds-serve.md +++ b/node.js/cds-serve.md @@ -215,14 +215,13 @@ app.use (cds.middlewares.before, protocol_adapter, cds.middlewares.after) ``` The standard set of middlewares uses the following order: - ```js cds.middlewares.before = [ - context(), // provides cds.context - trace(), // provides detailed trace logs when DEBUG=trace - auth(), // provides req.user & tenant + context(), // provides cds.context + trace(), // provides detailed trace logs when DEBUG=trace + auth(), // provides req.user & tenant ctx_auth(), // propagates auth results to cds.context - ctx_model(), // fills in cds.context.model + ctx_model(), // fills in cds.context.model ] ``` From 706a78ad8075b9ada81e01bba9ae76e6715d0a37 Mon Sep 17 00:00:00 2001 From: sjvans <30337871+sjvans@users.noreply.github.com> Date: Wed, 10 Jul 2024 10:37:08 +0200 Subject: [PATCH 04/10] Update node.js/cds-serve.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: René Jeglinsky --- node.js/cds-serve.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node.js/cds-serve.md b/node.js/cds-serve.md index 5153e4044e..718579ab6d 100644 --- a/node.js/cds-serve.md +++ b/node.js/cds-serve.md @@ -231,8 +231,8 @@ cds.middlewares.after = [ ] ``` -::: tip -In order for a custom error middleware to be invoked, it must be registered _before_ the built-in `cds_error_handler`. That is, it must be added, for example, via `cds.middlewares.after.unshift()`. +::: tip Custom error middleware before `cds_error_handler` +To invoke a custom error middleware successfully, you must register it _before_ the built-in `cds_error_handler`. You can achieve that, for example, by adding the middleware using `cds.middlewares.after.unshift()`. ::: ::: warning _Be aware of the interdependencies of middlewares_ From a78bba51d47bbcaa7121dc3cfb86440718b633db Mon Sep 17 00:00:00 2001 From: D050513 Date: Wed, 21 May 2025 15:46:12 +0200 Subject: [PATCH 05/10] Base Protocol Adapter --- node.js/cds-serve.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/node.js/cds-serve.md b/node.js/cds-serve.md index 2df0b9fe21..2cb5d44555 100644 --- a/node.js/cds-serve.md +++ b/node.js/cds-serve.md @@ -410,6 +410,12 @@ service CatalogService {} Be aware that using an absolute path will disallow serving the service at multiple protocols. +### Base Protocol Adapter + +All CAP-own protocol adapters extend a base protocol adapter that mounts the following middlewares: +1. `http_log`: log all incoming requests +2. `requires_check`: check the required roles for the respective service + ### Custom Protocol Adapter Similar to the configuration of the GraphQL Adapter, you can plug in your own protocol. From b124ec3cf3fc3dd1feb8a60b4a51d604763b27b0 Mon Sep 17 00:00:00 2001 From: D050513 Date: Tue, 27 May 2025 00:03:58 +0200 Subject: [PATCH 06/10] PATCH vs. PUT vs. Replace --- node.js/cds-serve.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/node.js/cds-serve.md b/node.js/cds-serve.md index 2cb5d44555..59aabd7e5c 100644 --- a/node.js/cds-serve.md +++ b/node.js/cds-serve.md @@ -410,6 +410,25 @@ service CatalogService {} Be aware that using an absolute path will disallow serving the service at multiple protocols. +### PATCH vs. PUT vs. Replace + +The HTTP method `PATCH` is meant for partial modification of an _existing resource_. +`PUT`, on the other hand, is meant for ensuring a resource exists +That is, if it doesn't yet exists, it gets created. +If it does exist, it gets updated to reflect the request's content. + +This content, however, may be incomplete. +By default, the values for not listed keys are not touched. +The rationale being that default values are known and clients have the option to send full representations, if necessary. + +The following table shows the Node.js runtime's configuration options and their respective default value: + +| Flag | Behavior | Default | +|----------------------------------------------|------------------------------------------|---------| +| cds.runtime.patch_as_upsert | Create resource if it does not yet exist | false | +| cds.runtime.put_as_upsert | Create resource if it does not yet exist | true | +| cds.runtime.put_as_replace | Payload is enriched with default values | false | + ### Base Protocol Adapter All CAP-own protocol adapters extend a base protocol adapter that mounts the following middlewares: From 053b75786f1699d277ae4df73c1baa2f64a0c5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Jeglinsky?= Date: Wed, 28 May 2025 09:07:21 +0200 Subject: [PATCH 07/10] Update node.js/cds-serve.md --- node.js/cds-serve.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node.js/cds-serve.md b/node.js/cds-serve.md index 59aabd7e5c..4c418ec8cd 100644 --- a/node.js/cds-serve.md +++ b/node.js/cds-serve.md @@ -425,9 +425,9 @@ The following table shows the Node.js runtime's configuration options and their | Flag | Behavior | Default | |----------------------------------------------|------------------------------------------|---------| -| cds.runtime.patch_as_upsert | Create resource if it does not yet exist | false | -| cds.runtime.put_as_upsert | Create resource if it does not yet exist | true | -| cds.runtime.put_as_replace | Payload is enriched with default values | false | +| cds.runtime.patch_as_upsert = false | Create resource if it does not yet exist | false | +| cds.runtime.put_as_upsert = true | Create resource if it does not yet exist | true | +| cds.runtime.put_as_replace = false | Payload is enriched with default values | false | ### Base Protocol Adapter From 4dd5abfc2007343f67bb282b753434b89bd9042c Mon Sep 17 00:00:00 2001 From: D050513 Date: Thu, 21 Aug 2025 11:53:00 +0200 Subject: [PATCH 08/10] rm cds.middlewares.after --- node.js/cds-serve.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/node.js/cds-serve.md b/node.js/cds-serve.md index 4c418ec8cd..5ca0034b21 100644 --- a/node.js/cds-serve.md +++ b/node.js/cds-serve.md @@ -208,7 +208,7 @@ srv/cat-service.js #> service implementation used by default For each service served at a certain protocol, the framework registers a configurable set of express middlewares by default like so: ```js -app.use (cds.middlewares.before, protocol_adapter, cds.middlewares.after) +app.use (cds.middlewares.before, protocol_adapter) ``` The standard set of middlewares uses the following order: @@ -222,12 +222,6 @@ cds.middlewares.before = [ ] ``` -```js -cds.middlewares.after = [ - cds_error_handler(), // provides final error handling -] -``` - ::: tip Custom error middleware before `cds_error_handler` To invoke a custom error middleware successfully, you must register it _before_ the built-in `cds_error_handler`. You can achieve that, for example, by adding the middleware using `cds.middlewares.after.unshift()`. ::: From 3d01f0b9754d04e68c4c45f40cf7bf1836375abf Mon Sep 17 00:00:00 2001 From: D050513 Date: Thu, 21 Aug 2025 11:54:03 +0200 Subject: [PATCH 09/10] more --- node.js/cds-serve.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/node.js/cds-serve.md b/node.js/cds-serve.md index 5ca0034b21..013a551d6a 100644 --- a/node.js/cds-serve.md +++ b/node.js/cds-serve.md @@ -222,10 +222,6 @@ cds.middlewares.before = [ ] ``` -::: tip Custom error middleware before `cds_error_handler` -To invoke a custom error middleware successfully, you must register it _before_ the built-in `cds_error_handler`. You can achieve that, for example, by adding the middleware using `cds.middlewares.after.unshift()`. -::: - ::: warning _Be aware of the interdependencies of middlewares_ _ctx_model_ requires that _cds.context_ middleware has run before. _ctx_auth_ requires that _authentication_ has run before. From 41f6d16d29f527dd56c9c8adba2532f02ba16cd2 Mon Sep 17 00:00:00 2001 From: D050513 Date: Thu, 21 Aug 2025 11:57:44 +0200 Subject: [PATCH 10/10] rm PATCH vs. PUT vs. Replace --- node.js/cds-serve.md | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/node.js/cds-serve.md b/node.js/cds-serve.md index 013a551d6a..94e5006bca 100644 --- a/node.js/cds-serve.md +++ b/node.js/cds-serve.md @@ -400,25 +400,6 @@ service CatalogService {} Be aware that using an absolute path will disallow serving the service at multiple protocols. -### PATCH vs. PUT vs. Replace - -The HTTP method `PATCH` is meant for partial modification of an _existing resource_. -`PUT`, on the other hand, is meant for ensuring a resource exists -That is, if it doesn't yet exists, it gets created. -If it does exist, it gets updated to reflect the request's content. - -This content, however, may be incomplete. -By default, the values for not listed keys are not touched. -The rationale being that default values are known and clients have the option to send full representations, if necessary. - -The following table shows the Node.js runtime's configuration options and their respective default value: - -| Flag | Behavior | Default | -|----------------------------------------------|------------------------------------------|---------| -| cds.runtime.patch_as_upsert = false | Create resource if it does not yet exist | false | -| cds.runtime.put_as_upsert = true | Create resource if it does not yet exist | true | -| cds.runtime.put_as_replace = false | Payload is enriched with default values | false | - ### Base Protocol Adapter All CAP-own protocol adapters extend a base protocol adapter that mounts the following middlewares: