From f175189d939d14e7f71695e81df364a873e641de Mon Sep 17 00:00:00 2001 From: Gladwin Dosunmu Date: Tue, 30 Apr 2024 23:44:07 +0100 Subject: [PATCH] update gateway references --- examples/react-app/.env.local.sample | 2 +- examples/react-app/package.json | 4 +-- .../{gateway => proxy}/.env.gateweaver.sample | 0 .../react-app/{gateway => proxy}/Dockerfile | 0 .../{gateway => proxy}/gateweaver.yml | 0 examples/react-app/src/App.tsx | 23 +++++++++-------- packages/cli/src/index.ts | 2 +- .../docs/docs/configuration/policies/cors.md | 2 +- .../docs/configuration/policies/rate-limit.md | 2 +- packages/e2e/jest.env.ts | 2 +- packages/e2e/tests/api-key/api-key.test.ts | 20 +++++++-------- packages/e2e/tests/api-key/gateweaver.yml | 4 +-- packages/e2e/tests/jwt/gateweaver.yml | 4 +-- packages/e2e/tests/jwt/jwt.test.ts | 20 +++++++-------- packages/e2e/tests/public/gateweaver.yml | 4 +-- packages/e2e/tests/public/public.test.ts | 25 ++++++++++--------- 16 files changed, 58 insertions(+), 56 deletions(-) rename examples/react-app/{gateway => proxy}/.env.gateweaver.sample (100%) rename examples/react-app/{gateway => proxy}/Dockerfile (100%) rename examples/react-app/{gateway => proxy}/gateweaver.yml (100%) diff --git a/examples/react-app/.env.local.sample b/examples/react-app/.env.local.sample index b0100f4..868092a 100644 --- a/examples/react-app/.env.local.sample +++ b/examples/react-app/.env.local.sample @@ -1 +1 @@ -VITE_GATEWAY_URL=http://localhost:8080 \ No newline at end of file +VITE_PROXY_URL=http://localhost:8080 \ No newline at end of file diff --git a/examples/react-app/package.json b/examples/react-app/package.json index d78a293..5a80426 100644 --- a/examples/react-app/package.json +++ b/examples/react-app/package.json @@ -4,8 +4,8 @@ "version": "0.0.0", "type": "module", "scripts": { - "gateway": "cd gateway && gateweaver start -w", - "dev": "npm run gateway & vite", + "proxy": "cd proxy && gateweaver start -w", + "dev": "npm run proxy & vite", "build": "tsc && vite build", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview" diff --git a/examples/react-app/gateway/.env.gateweaver.sample b/examples/react-app/proxy/.env.gateweaver.sample similarity index 100% rename from examples/react-app/gateway/.env.gateweaver.sample rename to examples/react-app/proxy/.env.gateweaver.sample diff --git a/examples/react-app/gateway/Dockerfile b/examples/react-app/proxy/Dockerfile similarity index 100% rename from examples/react-app/gateway/Dockerfile rename to examples/react-app/proxy/Dockerfile diff --git a/examples/react-app/gateway/gateweaver.yml b/examples/react-app/proxy/gateweaver.yml similarity index 100% rename from examples/react-app/gateway/gateweaver.yml rename to examples/react-app/proxy/gateweaver.yml diff --git a/examples/react-app/src/App.tsx b/examples/react-app/src/App.tsx index 8efb403..dfc42bf 100644 --- a/examples/react-app/src/App.tsx +++ b/examples/react-app/src/App.tsx @@ -1,23 +1,24 @@ import { useState } from "react"; import "./App.css"; -interface GatewayResponse { +interface ProxyResponse { authenticated: boolean; token: string; } function App() { - const [gatewayResponse, setGatewayResponse] = - useState(null); + const [proxyResponse, setProxyResponse] = useState( + null, + ); const handleClick = async () => { - if (gatewayResponse) { - setGatewayResponse(null); + if (proxyResponse) { + setProxyResponse(null); return; } try { - const BASE_URL = import.meta.env.VITE_GATEWAY_URL; + const BASE_URL = import.meta.env.VITE_PROXY_URL; const response = await fetch(`${BASE_URL}/example`); @@ -28,13 +29,13 @@ function App() { const data = await response.json(); - setGatewayResponse(data); + setProxyResponse(data); } catch (error) { console.error(error); } }; - const buttonText = gatewayResponse ? "Clear" : "Fetch data"; + const buttonText = proxyResponse ? "Clear" : "Fetch data"; return ( <> @@ -42,10 +43,10 @@ function App() {
- {gatewayResponse && ( + {proxyResponse && ( <> -

Response from Gateway:

-
{JSON.stringify(gatewayResponse, null, 2)}
+

Response from Proxy:

+
{JSON.stringify(proxyResponse, null, 2)}
)}
diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 9b972cd..ee3550a 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -15,7 +15,7 @@ const setupCLI = async () => { program .name("gateweaver") - .description("A CLI tool for managing gateweaver gateways") + .description("A CLI tool for managing gateweaver") .version(packageJson.default.version); startServerCommand(program); diff --git a/packages/docs/docs/configuration/policies/cors.md b/packages/docs/docs/configuration/policies/cors.md index 7e3738f..2053fb8 100644 --- a/packages/docs/docs/configuration/policies/cors.md +++ b/packages/docs/docs/configuration/policies/cors.md @@ -4,7 +4,7 @@ sidebar_position: 1 # CORS -The CORS (Cross-Origin Resource Sharing) policy allows you to tailor how endpoints on your gateway respond to cross-origin requests. +The CORS (Cross-Origin Resource Sharing) policy allows you to tailor how endpoints on your API Proxy respond to cross-origin requests. ## Options diff --git a/packages/docs/docs/configuration/policies/rate-limit.md b/packages/docs/docs/configuration/policies/rate-limit.md index 3c4c68a..7e933fa 100644 --- a/packages/docs/docs/configuration/policies/rate-limit.md +++ b/packages/docs/docs/configuration/policies/rate-limit.md @@ -4,7 +4,7 @@ sidebar_position: 2 # Rate Limit -The Rate limit policy allows you to control the rate at which requests to your gateway can be made, preventing abuse and ensuring fair use of resources. +The Rate limit policy allows you to control the rate at which requests to your API Proxy can be made, preventing abuse and ensuring fair use of resources. ## Options diff --git a/packages/e2e/jest.env.ts b/packages/e2e/jest.env.ts index 16b841b..aa1f92f 100644 --- a/packages/e2e/jest.env.ts +++ b/packages/e2e/jest.env.ts @@ -1,2 +1,2 @@ process.env.NODE_ENV = "test"; -process.env.PORT = "6001"; // Port for the Gateway Server +process.env.PORT = "6001"; // Port for the Gateweaver Server diff --git a/packages/e2e/tests/api-key/api-key.test.ts b/packages/e2e/tests/api-key/api-key.test.ts index 6ad4c69..267525d 100644 --- a/packages/e2e/tests/api-key/api-key.test.ts +++ b/packages/e2e/tests/api-key/api-key.test.ts @@ -9,37 +9,37 @@ const RATE_LIMITED_PATH = "/api-key/rate-limited"; const TEST_API_KEY = "test-api-key"; describe("e2e - API Key Protected Endpoint", () => { - let gateway: Server; + let gateweaver: Server; beforeAll(async () => { const configPath = path.join(__dirname, "gateweaver.yml"); - gateway = await startServer(configPath, false); + gateweaver = await startServer(configPath, false); }); afterAll(() => { - gateway?.close(); + gateweaver?.close(); }); it("should return a 200 status, correct body and headers when accessing an API Key protected endpoint with a correct API Key", async () => { - const response = await request(gateway) + const response = await request(gateweaver) .get(MOCK_PATH) .set("x-api-key", TEST_API_KEY); expect(response.status).toBe(200); - expect(response.body).toEqual({ message: "Message from gateway query" }); + expect(response.body).toEqual({ message: "Message from gateweaver query" }); checkResponseHeaders(response); }); it("should return a 401 status when an API Key protected endpoint is accessed without an API Key", async () => { - const response = await request(gateway).get(MOCK_PATH); + const response = await request(gateweaver).get(MOCK_PATH); expect(response.status).toBe(401); expect(response.body).toEqual({ error: "API Key Required" }); }); it("should return a 401 status when an API Key protected endpoint is accessed with an invalid API Key", async () => { - const response = await request(gateway) + const response = await request(gateweaver) .get(MOCK_PATH) .set("x-api-key", "invalid-api-key"); @@ -48,13 +48,13 @@ describe("e2e - API Key Protected Endpoint", () => { }); it("should return a 429 status when an API Key protected endpoint is rate limited", async () => { - await request(gateway) + await request(gateweaver) .get(RATE_LIMITED_PATH) .set("x-api-key", TEST_API_KEY); - await request(gateway) + await request(gateweaver) .get(RATE_LIMITED_PATH) .set("x-api-key", TEST_API_KEY); - const rateLimitedResponse = await request(gateway) + const rateLimitedResponse = await request(gateweaver) .get(RATE_LIMITED_PATH) .set("x-api-key", TEST_API_KEY); diff --git a/packages/e2e/tests/api-key/gateweaver.yml b/packages/e2e/tests/api-key/gateweaver.yml index 7bd6857..e2ba6e8 100644 --- a/packages/e2e/tests/api-key/gateweaver.yml +++ b/packages/e2e/tests/api-key/gateweaver.yml @@ -16,7 +16,7 @@ endpoints: headers: Authorization: "Bearer mock-server-token" query: - message: "Message from gateway query" + message: "Message from gateweaver query" response: headers: remove-header: "" @@ -32,7 +32,7 @@ endpoints: headers: Authorization: "Bearer mock-server-token" query: - message: "Message from gateway query" + message: "Message from gateweaver query" policies: - rateLimit - apiKey diff --git a/packages/e2e/tests/jwt/gateweaver.yml b/packages/e2e/tests/jwt/gateweaver.yml index c463cbc..8c1e45c 100644 --- a/packages/e2e/tests/jwt/gateweaver.yml +++ b/packages/e2e/tests/jwt/gateweaver.yml @@ -19,7 +19,7 @@ endpoints: headers: Authorization: "Bearer mock-server-token" query: - message: "Message from gateway query" + message: "Message from gateweaver query" response: headers: remove-header: "" @@ -35,7 +35,7 @@ endpoints: headers: Authorization: "Bearer mock-server-token" query: - message: "Message from gateway query" + message: "Message from gateweaver query" policies: - rateLimit - jwt diff --git a/packages/e2e/tests/jwt/jwt.test.ts b/packages/e2e/tests/jwt/jwt.test.ts index 7edd964..caaba5c 100644 --- a/packages/e2e/tests/jwt/jwt.test.ts +++ b/packages/e2e/tests/jwt/jwt.test.ts @@ -14,37 +14,37 @@ describe("e2e - JWT Protected Endpoint", () => { issuer: "test-issuer", }); - let gateway: Server; + let gateweaver: Server; beforeAll(async () => { const configPath = path.join(__dirname, "gateweaver.yml"); - gateway = await startServer(configPath, false); + gateweaver = await startServer(configPath, false); }); afterAll(() => { - gateway?.close(); + gateweaver?.close(); }); it("should return a 200 status, correct body and headers when accessing a JWT protected endpoint with a correct Token", async () => { - const response = await request(gateway) + const response = await request(gateweaver) .get(MOCK_PATH) .set("Authorization", `Bearer ${token}`); expect(response.status).toBe(200); - expect(response.body).toEqual({ message: "Message from gateway query" }); + expect(response.body).toEqual({ message: "Message from gateweaver query" }); checkResponseHeaders(response); }); it("should return a 401 status when a JWT protected endpoint is accessed without a Token", async () => { - const response = await request(gateway).get(MOCK_PATH); + const response = await request(gateweaver).get(MOCK_PATH); expect(response.status).toBe(401); expect(response.body).toEqual({ error: "Invalid Authorization Token" }); }); it("should return a 401 status when a JWT protected endpoint is accessed with an invalid Token", async () => { - const response = await request(gateway) + const response = await request(gateweaver) .get(MOCK_PATH) .set("Authorization", `Bearer invalid-token`); @@ -53,13 +53,13 @@ describe("e2e - JWT Protected Endpoint", () => { }); it("should return a 429 status when a JWT protected endpoint is rate limited", async () => { - await request(gateway) + await request(gateweaver) .get(RATE_LIMITED_PATH) .set("Authorization", `Bearer ${token}`); - await request(gateway) + await request(gateweaver) .get(RATE_LIMITED_PATH) .set("Authorization", `Bearer ${token}`); - const rateLimitedResponse = await request(gateway) + const rateLimitedResponse = await request(gateweaver) .get(RATE_LIMITED_PATH) .set("Authorization", `Bearer ${token}`); diff --git a/packages/e2e/tests/public/gateweaver.yml b/packages/e2e/tests/public/gateweaver.yml index fe16738..e4b85e9 100644 --- a/packages/e2e/tests/public/gateweaver.yml +++ b/packages/e2e/tests/public/gateweaver.yml @@ -13,7 +13,7 @@ endpoints: headers: Authorization: "Bearer mock-server-token" query: - message: "Message from gateway query" + message: "Message from gateweaver query" response: headers: remove-header: "" @@ -28,6 +28,6 @@ endpoints: headers: Authorization: "Bearer mock-server-token" query: - message: "Message from gateway query" + message: "Message from gateweaver query" policies: - rateLimit diff --git a/packages/e2e/tests/public/public.test.ts b/packages/e2e/tests/public/public.test.ts index 277e410..2cb0734 100644 --- a/packages/e2e/tests/public/public.test.ts +++ b/packages/e2e/tests/public/public.test.ts @@ -8,28 +8,28 @@ const MOCK_PATH = "/public/mock"; const RATE_LIMITED_PATH = "/public/rate-limited"; describe("e2e - Public Endpoint", () => { - let gateway: Server; + let gateweaver: Server; beforeAll(async () => { const configPath = path.join(__dirname, "gateweaver.yml"); - gateway = await startServer(configPath, false); + gateweaver = await startServer(configPath, false); }); afterAll(() => { - gateway?.close(); + gateweaver?.close(); }); it("should return a 200 status, correct body and headers when accessing a public GET endpoint", async () => { - const response = await request(gateway).get(MOCK_PATH); + const response = await request(gateweaver).get(MOCK_PATH); expect(response.status).toBe(200); - expect(response.body).toEqual({ message: "Message from gateway query" }); + expect(response.body).toEqual({ message: "Message from gateweaver query" }); checkResponseHeaders(response); }); it("should return a 200 status, correct body and headers when accessing a public POST endpoint", async () => { - const response = await request(gateway) + const response = await request(gateweaver) .post(MOCK_PATH) .send({ name: "Gateweaver" }); @@ -40,7 +40,7 @@ describe("e2e - Public Endpoint", () => { }); it("should return a 200 status, correct body and headers when accessing a public PUT endpoint", async () => { - const response = await request(gateway) + const response = await request(gateweaver) .put(MOCK_PATH) .send({ name: "Gateweaver" }); @@ -51,7 +51,7 @@ describe("e2e - Public Endpoint", () => { }); it("should return a 200 status, correct body and headers when accessing a public PATCH endpoint", async () => { - const response = await request(gateway) + const response = await request(gateweaver) .patch(MOCK_PATH) .send({ name: "Gateweaver" }); @@ -62,7 +62,7 @@ describe("e2e - Public Endpoint", () => { }); it("should return a 200 status, correct body and headers when accessing a public DELETE endpoint", async () => { - const response = await request(gateway).delete(MOCK_PATH); + const response = await request(gateweaver).delete(MOCK_PATH); expect(response.status).toBe(200); expect(response.body).toEqual({ @@ -73,9 +73,10 @@ describe("e2e - Public Endpoint", () => { }); it("should return a 429 status when a public endpoint is rate limited", async () => { - await request(gateway).get(RATE_LIMITED_PATH); - await request(gateway).get(RATE_LIMITED_PATH); - const rateLimitedResponse = await request(gateway).get(RATE_LIMITED_PATH); + await request(gateweaver).get(RATE_LIMITED_PATH); + await request(gateweaver).get(RATE_LIMITED_PATH); + const rateLimitedResponse = + await request(gateweaver).get(RATE_LIMITED_PATH); expect(rateLimitedResponse.status).toBe(429); expect(rateLimitedResponse.text).toBe(