Skip to content

Commit

Permalink
chore: add Github CI
Browse files Browse the repository at this point in the history
  • Loading branch information
FranklinWaller committed Aug 19, 2024
1 parent a45429f commit bdbc8be
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 102 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: 'Test'
on: [pull_request, push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2

- name: 📦 Install dependencies
run: bun install

- name: 📝 Check formatting
run: bun install

- name: 🧪 Test project
run: bun test
179 changes: 88 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Allows Data Providers to expose their (private) APIs on the SEDA network. Only e
## Set up

Install bun:

```sh
curl -fsSL https://bun.sh/install | bash
```
Expand All @@ -31,8 +32,8 @@ bun start init

This will generate two files:

* `config.json`: Configure where routes are going to and what to inject (ex: headers)
* `data-proxy-private-key.json`: Private key that signs the HTTP response. This key is registered on the SEDA chain (see below). If required you can also use the `SEDA_DATA_PROXY_PRIVATE_KEY` environment variable to expose the private key to the node.
- `config.json`: Configure where routes are going to and what to inject (ex: headers)
- `data-proxy-private-key.json`: Private key that signs the HTTP response. This key is registered on the SEDA chain (see below). If required you can also use the `SEDA_DATA_PROXY_PRIVATE_KEY` environment variable to expose the private key to the node.

Now you can run the node:

Expand All @@ -54,39 +55,38 @@ The node will auto sign the response and include two headers: `x-seda-signature`

## Proxy rules

* Request query params are forwared to the `upstreamUrl`
* Request headers except `host` are forwared to the `upstreamUrl`
* Request Body is forwared to the `upstreamUrl`
* By default only the upstream header `content-type` is given back. This can however be configured to include more.
* The full body is given back as a response. This can be reduced with using `jsonPath`

- Request query params are forwared to the `upstreamUrl`
- Request headers except `host` are forwared to the `upstreamUrl`
- Request Body is forwared to the `upstreamUrl`
- By default only the upstream header `content-type` is given back. This can however be configured to include more.
- The full body is given back as a response. This can be reduced with using `jsonPath`

## Configuration

The config file allows you to configure multiple routes:

```jsonc
{
"routeGroup": "proxy",
"routes": [
{
"path": "/eth-usd",
"upstreamUrl": "https://myapi.com/eth-usd",
// Default is GET
"headers": {
"x-api-key": "some-api-key"
}
},
{
"path": "/btc-usd",
"upstreamUrl": "https://myapi.com/btc-usd",
// Allows for multiple method setting
"method": ["GET", "HEAD"],
"headers": {
"x-api-key": "some-api-key"
}
}
]
"routeGroup": "proxy",
"routes": [
{
"path": "/eth-usd",
"upstreamUrl": "https://myapi.com/eth-usd",
// Default is GET
"headers": {
"x-api-key": "some-api-key",
},
},
{
"path": "/btc-usd",
"upstreamUrl": "https://myapi.com/btc-usd",
// Allows for multiple method setting
"method": ["GET", "HEAD"],
"headers": {
"x-api-key": "some-api-key",
},
},
],
}
```

Expand All @@ -96,19 +96,19 @@ The config.json has support for using variable routes by using `:varName`:

```jsonc
{
"routeGroup": "proxy",
"routes": [
{
"path": "/:coinA/:coinB",
// Use {} to inject route variables
"upstreamUrl": "https://myapi.com/{:coinA}-{:coinB}",
"headers": {
"x-api-key": "some-api-key",
// Can also be injected in the header
"x-custom": "{:coinA}"
}
}
]
"routeGroup": "proxy",
"routes": [
{
"path": "/:coinA/:coinB",
// Use {} to inject route variables
"upstreamUrl": "https://myapi.com/{:coinA}-{:coinB}",
"headers": {
"x-api-key": "some-api-key",
// Can also be injected in the header
"x-custom": "{:coinA}",
},
},
],
}
```

Expand All @@ -118,18 +118,18 @@ If you don't want to expose all API info you can use `jsonPath` to reduce the re

```jsonc
{
"routeGroup": "proxy",
"routes": [
{
"path": "/planets/:planet",
"upstreamUrl": "https://swapi.dev/api/planets/{:planet}",
// Calling the API http://localhost:5384/proxy/planets/1 will only return "Tatooine" and omit the rest
"jsonPath": "$.name",
"headers": {
"x-api-key": "some-api-key"
}
}
]
"routeGroup": "proxy",
"routes": [
{
"path": "/planets/:planet",
"upstreamUrl": "https://swapi.dev/api/planets/{:planet}",
// Calling the API http://localhost:5384/proxy/planets/1 will only return "Tatooine" and omit the rest
"jsonPath": "$.name",
"headers": {
"x-api-key": "some-api-key",
},
},
],
}
```

Expand All @@ -139,21 +139,18 @@ By default the data proxy node will only forward the `content-type` as a respons

```jsonc
{
"routeGroup": "proxy",
"routes": [
{
"path": "/planets/:planet",
"upstreamUrl": "https://swapi.dev/api/planets/{:planet}",
// Now the API will also return the server header from SWApi
"forwardRepsonseHeaders": [
"content-type",
"server"
],
"headers": {
"x-api-key": "some-api-key"
}
}
]
"routeGroup": "proxy",
"routes": [
{
"path": "/planets/:planet",
"upstreamUrl": "https://swapi.dev/api/planets/{:planet}",
// Now the API will also return the server header from SWApi
"forwardRepsonseHeaders": ["content-type", "server"],
"headers": {
"x-api-key": "some-api-key",
},
},
],
}
```

Expand All @@ -163,17 +160,17 @@ Sometimes you don't want to expose your API key in a config file, or you have mu

```jsonc
{
"routeGroup": "proxy",
"routes": [
{
// Everything will be injected in the URL
"path": "/*",
"upstreamUrl": "https://swapi.dev/api/{*}",
"headers": {
"x-api-key": "{$SECRET_API_KEY}"
}
}
]
"routeGroup": "proxy",
"routes": [
{
// Everything will be injected in the URL
"path": "/*",
"upstreamUrl": "https://swapi.dev/api/{*}",
"headers": {
"x-api-key": "{$SECRET_API_KEY}",
},
},
],
}
```

Expand All @@ -183,16 +180,16 @@ The Data Proxy node has support for wildcard routes, which allows you to quickly

```jsonc
{
"routeGroup": "proxy",
"routes": [
{
// Everything will be injected in the URL
"path": "/*",
"upstreamUrl": "https://swapi.dev/api/{*}",
"headers": {
"x-api-key": "some-api-key"
}
}
]
"routeGroup": "proxy",
"routes": [
{
// Everything will be injected in the URL
"path": "/*",
"upstreamUrl": "https://swapi.dev/api/{*}",
"headers": {
"x-api-key": "some-api-key",
},
},
],
}
```
```
10 changes: 0 additions & 10 deletions index.ts

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"proto": "cd workspace/data-proxy-sdk && bun run proto",
"start": "bun run ./workspace/data-proxy",
"fmt": "bunx biome check --write ."
"fmt": "bunx biome check --write .",
"check-fmt": "bunx biome check ."
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
Expand Down

0 comments on commit bdbc8be

Please sign in to comment.