Skip to content

Commit

Permalink
create examples (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
gladwindos committed Apr 12, 2024
1 parent ff7911f commit 2b2d4fe
Show file tree
Hide file tree
Showing 35 changed files with 454 additions and 2 deletions.
3 changes: 3 additions & 0 deletions examples/jwt-auth0/.env.gateweaver.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE_ENV=development
AUTH0_AUDIENCE=your_auth0_audience
AUTH0_DOMAIN=your_auth0_domain
2 changes: 2 additions & 0 deletions examples/jwt-auth0/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env.gateweaver
3 changes: 3 additions & 0 deletions examples/jwt-auth0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM gateweaver/server:0.0.27
COPY gateweaver.yml /app/gateweaver.yml
ENV NODE_ENV=production
14 changes: 14 additions & 0 deletions examples/jwt-auth0/gateweaver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
policyDefinitions:
jwt:
jwksUri: "https://${AUTH0_DOMAIN}/.well-known/jwks.json"
audience: "${AUTH0_AUDIENCE}"
issuer: "https://${AUTH0_DOMAIN}/"
algorithms:
- "RS256"

endpoints:
- path: "/example"
target:
url: "https://httpbin.org/get"
policies:
- jwt
16 changes: 16 additions & 0 deletions examples/jwt-auth0/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "jwt-auth0",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "gateweaver start",
"dev": "gateweaver start -w"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@gateweaver/cli": "^0.0.27"
}
}
2 changes: 2 additions & 0 deletions examples/jwt-firebase/.env.gateweaver.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NODE_ENV=development
PROJECT_ID=your_firebase_project_id
2 changes: 2 additions & 0 deletions examples/jwt-firebase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env.gateweaver
3 changes: 3 additions & 0 deletions examples/jwt-firebase/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM gateweaver/server:0.0.27
COPY gateweaver.yml /app/gateweaver.yml
ENV NODE_ENV=production
14 changes: 14 additions & 0 deletions examples/jwt-firebase/gateweaver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
policyDefinitions:
jwt:
jwksUri: "https://www.googleapis.com/service_accounts/v1/jwk/[email protected]"
audience: "${PROJECT_ID}"
issuer: "https://securetoken.google.com/${PROJECT_ID}"
algorithms:
- "RS256"

endpoints:
- path: "/example"
target:
url: "https://httpbin.org/get"
policies:
- jwt
16 changes: 16 additions & 0 deletions examples/jwt-firebase/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "jwt-firebase",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "gateweaver start",
"dev": "gateweaver start -w"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@gateweaver/cli": "^0.0.27"
}
}
2 changes: 2 additions & 0 deletions examples/jwt-supabase/.env.gateweaver.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NODE_ENV=development
SUPABASE_JWT_SECRET=your_supabase_jwt_secret
2 changes: 2 additions & 0 deletions examples/jwt-supabase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env.gateweaver
3 changes: 3 additions & 0 deletions examples/jwt-supabase/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM gateweaver/server:0.0.27
COPY gateweaver.yml /app/gateweaver.yml
ENV NODE_ENV=production
12 changes: 12 additions & 0 deletions examples/jwt-supabase/gateweaver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
policyDefinitions:
jwt:
secret: ${SUPABASE_JWT_SECRET}
algorithms:
- "HS256"

endpoints:
- path: "/example"
target:
url: "https://httpbin.org/get"
policies:
- jwt
16 changes: 16 additions & 0 deletions examples/jwt-supabase/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "jwt-supabase",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "gateweaver start",
"dev": "gateweaver start -w"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@gateweaver/cli": "^0.0.27"
}
}
1 change: 1 addition & 0 deletions examples/react-app/.env.local.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GATEWAY_URL=http:https://localhost:8080
18 changes: 18 additions & 0 deletions examples/react-app/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
26 changes: 26 additions & 0 deletions examples/react-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

.env.gateweaver
3 changes: 3 additions & 0 deletions examples/react-app/gateway/.env.gateweaver.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE_ENV=development
AUTH_TOKEN=example-token
CLIENT_URL=http:https://localhost:5173
3 changes: 3 additions & 0 deletions examples/react-app/gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM gateweaver/server:0.0.27
COPY gateweaver.yml /app/gateweaver.yml
ENV NODE_ENV=production
13 changes: 13 additions & 0 deletions examples/react-app/gateway/gateweaver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
policyDefinitions:
cors:
origin: "${CLIENT_URL}"

endpoints:
- path: "/example"
target:
url: "https://httpbin.org/bearer"
request:
headers:
Authorization: "Bearer ${AUTH_TOKEN}"
policies:
- cors
13 changes: 13 additions & 0 deletions examples/react-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
30 changes: 30 additions & 0 deletions examples/react-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "react-app",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"gateway:start": "cd gateway && gateweaver start -w",
"dev": "npm run gateway:start & vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@gateweaver/cli": "^0.0.27",
"@types/react": "^18.2.75",
"@types/react-dom": "^18.2.24",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^9.0.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"typescript": "^5.4.4",
"vite": "^5.2.8"
}
}
1 change: 1 addition & 0 deletions examples/react-app/public/vite.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions examples/react-app/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
64 changes: 64 additions & 0 deletions examples/react-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useState } from "react";
import reactLogo from "./assets/react.svg";
import viteLogo from "/vite.svg";
import "./App.css";

interface GatewayResponse {
authenticated: boolean;
token: string;
}

function App() {
const [gatewayResponse, setGatewayResponse] =
useState<GatewayResponse | null>(null);

const handleClick = async () => {
try {
const BASE_URL = import.meta.env.VITE_GATEWAY_URL;

const response = await fetch(`${BASE_URL}/example`);
if (!response.ok) {
throw new Error(`HTTP error status: ${response.status}`);
}

const data = await response.json();
setGatewayResponse(data);
} catch (error) {
console.error(error);
}
};

return (
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>React App</h1>
<div className="card">
<p>
Click the button below to call the gateway's /example endpoint, which
sends the request to{" "}
<a href="https://httpbin.org/#/Auth/get_bearer" target="_blank">
https://httpbin.org/bearer
</a>{" "}
and adds an Authorization header with a bearer token.
</p>
<button onClick={handleClick}>Click me</button>

{gatewayResponse && (
<>
<h4>Response from Gateway:</h4>
<pre>{JSON.stringify(gatewayResponse, null, 2)}</pre>
</>
)}
</div>
</>
);
}

export default App;
1 change: 1 addition & 0 deletions examples/react-app/src/assets/react.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2b2d4fe

Please sign in to comment.