Skip to content

Commit 89397c8

Browse files
authored
extend: Remove 'flow' child from global (#2527)
- update examples and tests
1 parent 91638f1 commit 89397c8

4 files changed

Lines changed: 45 additions & 15 deletions

File tree

core/src/main/java/com/predic8/membrane/core/interceptor/GlobalInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @description The global chain applies plugins to all endpoints, enabling centralized features
2323
* such as global user authentication, logging, and other cross-cutting concerns.
2424
*/
25-
@MCElement(name = "global", excludeFromFlow = true, component = false, topLevel = true)
25+
@MCElement(name = "global", excludeFromFlow = true, component = false, topLevel = true, noEnvelope = true)
2626
public class GlobalInterceptor extends AbstractFlowWithChildrenInterceptor {
2727

2828
@Override

distribution/examples/extending-membrane/global-interceptor/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ Some functionalities, such as authentication and rate limiting, are required acr
1111
2. **Test the APIs:**
1212
- **API 1 (Port 2000) → Returns `200 OK`**
1313
```sh
14-
curl -i http://localhost:2000
14+
curl -i http://localhost:2000/foo
1515
```
1616
- **API 2 (Port 2001) → Returns `404 Not Found`**
1717
```sh
18-
curl -i http://localhost:2001
18+
curl -i http://localhost:2001/bar
1919
```
2020
**Check the request:** both contain CORS headers
21-
3. **Check `proxies.xml`** to see how the global interceptors are applied.
21+
3. **Check `apis.yaml`** to see how the global interceptors are applied.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# yaml-language-server: $schema=https://www.membrane-api.io/v7.0.4.json
2+
3+
global:
4+
- log:
5+
message: "Path: ${path}"
6+
- response:
7+
- setHeader:
8+
name: Access-Control-Allow-Origin
9+
value: "*"
10+
- setHeader:
11+
name: Access-Control-Allow-Methods
12+
value: GET, POST
13+
- setHeader:
14+
name: Access-Control-Allow-Headers
15+
value: Content-Type
16+
17+
---
18+
19+
api:
20+
port: 2000
21+
flow:
22+
- return:
23+
status: 200
24+
25+
---
26+
27+
api:
28+
port: 2001
29+
flow:
30+
- return:
31+
status: 404

distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/GlobalInterceptorExampleTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
package com.predic8.membrane.examples.withoutinternet.test;
1616

17-
import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
18-
import org.junit.jupiter.api.Test;
17+
import com.predic8.membrane.examples.util.*;
18+
import org.junit.jupiter.api.*;
1919

20-
import static io.restassured.RestAssured.given;
20+
import static com.predic8.membrane.core.http.Header.*;
21+
import static io.restassured.RestAssured.*;
2122

2223
public class GlobalInterceptorExampleTest extends AbstractSampleMembraneStartStopTestcase {
2324

@@ -28,30 +29,28 @@ protected String getExampleDirName() {
2829

2930
// @formatter:off
3031
@Test
31-
public void request1() {
32+
void request1() {
3233
given()
3334
.when()
3435
.get("http://localhost:2000")
3536
.then()
3637
.assertThat()
3738
.header("Access-Control-Allow-Origin", "*")
38-
.header("Access-Control-Allow-Methods", "*")
39-
.header("Access-Control-Allow-Headers", "*")
40-
.header("Access-Control-Allow-Credentials", "*")
39+
.header("Access-Control-Allow-Methods", "GET, POST")
40+
.header("Access-Control-Allow-Headers", CONTENT_TYPE)
4141
.statusCode(200);
4242
}
4343

4444
@Test
45-
public void request2() {
45+
void request2() {
4646
given()
4747
.when()
4848
.get("http://localhost:2001")
4949
.then()
5050
.assertThat()
5151
.header("Access-Control-Allow-Origin", "*")
52-
.header("Access-Control-Allow-Methods", "*")
53-
.header("Access-Control-Allow-Headers", "*")
54-
.header("Access-Control-Allow-Credentials", "*")
52+
.header("Access-Control-Allow-Methods", "GET, POST")
53+
.header("Access-Control-Allow-Headers", CONTENT_TYPE)
5554
.statusCode(404);
5655
}
5756
// @formatter:on

0 commit comments

Comments
 (0)