Skip to content

Commit

Permalink
update gateway references
Browse files Browse the repository at this point in the history
  • Loading branch information
gladwindos committed Apr 30, 2024
1 parent b798952 commit f175189
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 56 deletions.
2 changes: 1 addition & 1 deletion examples/react-app/.env.local.sample
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_GATEWAY_URL=http:https://localhost:8080
VITE_PROXY_URL=http:https://localhost:8080
4 changes: 2 additions & 2 deletions examples/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 12 additions & 11 deletions examples/react-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -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<GatewayResponse | null>(null);
const [proxyResponse, setProxyResponse] = useState<ProxyResponse | null>(
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`);

Expand All @@ -28,24 +29,24 @@ 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 (
<>
<h1>React App</h1>
<div className="card">
<button onClick={handleClick}>{buttonText}</button>

{gatewayResponse && (
{proxyResponse && (
<>
<h4>Response from Gateway:</h4>
<pre>{JSON.stringify(gatewayResponse, null, 2)}</pre>
<h4>Response from Proxy:</h4>
<pre>{JSON.stringify(proxyResponse, null, 2)}</pre>
</>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/docs/configuration/policies/cors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/docs/docs/configuration/policies/rate-limit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/jest.env.ts
Original file line number Diff line number Diff line change
@@ -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
20 changes: 10 additions & 10 deletions packages/e2e/tests/api-key/api-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/tests/api-key/gateweaver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand All @@ -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
4 changes: 2 additions & 2 deletions packages/e2e/tests/jwt/gateweaver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand All @@ -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
20 changes: 10 additions & 10 deletions packages/e2e/tests/jwt/jwt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);

Expand All @@ -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}`);

Expand Down
4 changes: 2 additions & 2 deletions packages/e2e/tests/public/gateweaver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand All @@ -28,6 +28,6 @@ endpoints:
headers:
Authorization: "Bearer mock-server-token"
query:
message: "Message from gateway query"
message: "Message from gateweaver query"
policies:
- rateLimit
25 changes: 13 additions & 12 deletions packages/e2e/tests/public/public.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" });

Expand All @@ -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" });

Expand All @@ -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" });

Expand All @@ -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({
Expand All @@ -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(
Expand Down

0 comments on commit f175189

Please sign in to comment.