Skip to content

Commit

Permalink
updated readme + unit tests with jest
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Sep 26, 2024
1 parent 7e61026 commit 5326ae8
Show file tree
Hide file tree
Showing 14 changed files with 12,384 additions and 6,939 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
.mf
.env
.dev.vars
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,89 @@

![freeway overview diagram](./docs/freeway.png)

## Running Locally

1. Install the project
```sh
npm i
```

2. CloudFlare Authentication
```sh
npx wrangler login
```

3. Get Your Account Id
```sh
npx wrangler whoami
```

4. Add your configs to `wrangler.toml`
```sh
[env.YOUR_USERNAME]
workers_dev = true
account_id = "YOUR_ACCOUNT_ID"
r2_buckets = [
{ binding = "CARPARK", bucket_name = "carpark-YOUR_USERNAME-0", preview_bucket_name = "carpark-YOUR_USERNAME-preview-0" }
]

[env.YOUR_USERNAME.vars]
DEBUG = "true"
CONTENT_CLAIMS_SERVICE_URL = "https://dev.claims.web3.storage"
```
If you want to enable the Rate Limiter and KV add the following too:
```sh
[[env.YOUR_USERNAME.unsafe.bindings]]
name = "RATE_LIMITER"
type = "ratelimit"
namespace_id = "0"
simple = { limit = 100, period = 60 }

[[env.YOUR_USERNAME.kv_namespaces]]
binding = "AUTH_TOKEN_METADATA"
id = "YOUR_TOKEN" //FIXME how to obtain this token?
```
5. Start local server
```sh
npx wrangler dev -e YOUR_USERNAME
```
### Additional Tooling
*Kubo*: An IPFS implementation in Go
We are going to use it to save testing content and get valid CIDs.
```sh
docker pull ipfs/kubo:latest
docker run --rm -it --net=host ipfs/kubo:latest
```
Then add the sample content to get a valid CID for testing
```sh
echo "hello world" | ipfs add --cid-version=1
```
6. Sample Request
```sh
curl -XGET -i http://localhost
```
## Testing
Freeway is using miniflare v3 for testing which allows you to define the testing configurations in the JavaScript code (see `src/test/index.spec.js`).
Note:
- Miniflare v3 doesn't support the Rate Limiting bidding for now, so we need to mock the rate limiting API to be able to use it in tests and in local development?
In order to run the existing tests you can execute the following command:
```sh
npm run test
```
## Contributing
Feel free to join in. All welcome. Please read our [contributing guidelines](https://github.com/web3-storage/freeway/blob/main/CONTRIBUTING.md) and/or [open an issue](https://github.com/web3-storage/freeway/issues)!
Expand Down
13 changes: 13 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
},
"modules": false
}
]
]
}
Loading

0 comments on commit 5326ae8

Please sign in to comment.