Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @description The global chain applies plugins to all endpoints, enabling centralized features
* such as global user authentication, logging, and other cross-cutting concerns.
*/
@MCElement(name = "global", excludeFromFlow = true, component = false, topLevel = true)
@MCElement(name = "global", excludeFromFlow = true, component = false, topLevel = true, noEnvelope = true)
public class GlobalInterceptor extends AbstractFlowWithChildrenInterceptor {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Some functionalities, such as authentication and rate limiting, are required acr
2. **Test the APIs:**
- **API 1 (Port 2000) → Returns `200 OK`**
```sh
curl -i http://localhost:2000
curl -i http://localhost:2000/foo
```
- **API 2 (Port 2001) → Returns `404 Not Found`**
```sh
curl -i http://localhost:2001
curl -i http://localhost:2001/bar
```
**Check the request:** both contain CORS headers
3. **Check `proxies.xml`** to see how the global interceptors are applied.
3. **Check `apis.yaml`** to see how the global interceptors are applied.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# yaml-language-server: $schema=https://www.membrane-api.io/v7.0.4.json

global:
- log:
message: "Path: ${path}"
- response:
- setHeader:
name: Access-Control-Allow-Origin
value: "*"
- setHeader:
name: Access-Control-Allow-Methods
value: GET, POST
- setHeader:
name: Access-Control-Allow-Headers
value: Content-Type

---

api:
port: 2000
flow:
- return:
status: 200

---

api:
port: 2001
flow:
- return:
status: 404
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

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

import com.predic8.membrane.examples.util.AbstractSampleMembraneStartStopTestcase;
import org.junit.jupiter.api.Test;
import com.predic8.membrane.examples.util.*;
import org.junit.jupiter.api.*;

import static io.restassured.RestAssured.given;
import static com.predic8.membrane.core.http.Header.*;
import static io.restassured.RestAssured.*;

public class GlobalInterceptorExampleTest extends AbstractSampleMembraneStartStopTestcase {

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

// @formatter:off
@Test
public void request1() {
void request1() {
given()
.when()
.get("http://localhost:2000")
.then()
.assertThat()
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "*")
.header("Access-Control-Allow-Headers", "*")
.header("Access-Control-Allow-Credentials", "*")
.header("Access-Control-Allow-Methods", "GET, POST")
.header("Access-Control-Allow-Headers", CONTENT_TYPE)
.statusCode(200);
}

@Test
public void request2() {
void request2() {
given()
.when()
.get("http://localhost:2001")
.then()
.assertThat()
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "*")
.header("Access-Control-Allow-Headers", "*")
.header("Access-Control-Allow-Credentials", "*")
.header("Access-Control-Allow-Methods", "GET, POST")
.header("Access-Control-Allow-Headers", CONTENT_TYPE)
.statusCode(404);
}
// @formatter:on
Expand Down
Loading