https://github.com/visini/cloudflare-workers-typescript-cors
https://github.com/visini/cloudflare-workers-typescript-cors
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/visini/cloudflare-workers-typescript-cors
- Owner: visini
- Created: 2022-04-12T17:18:58.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-12T17:20:21.000Z (about 4 years ago)
- Last Synced: 2025-01-28T14:44:57.040Z (over 1 year ago)
- Language: TypeScript
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# esbuild-typescript-modules-workers-with-cors
See https://github.com/codewithkristian/esbuild-typescript-modules-workers-template
This adds support for:
- CORS
- Routing via `itty-router`
## Install
- Run `yarn`
- Develop via `make dev` (see `wrangler.toml`) and publish via `wrangler publish`
## Test CORS for GET
Example: Run below in Safari dev console while on `https://dash.cloudflare.com`
```js
const WORKER_URL = "https://foo-worker.workers.dev"
const API_KEY = "SECRET"
await fetch(WORKER_URL + "/foo", {
method: "GET",
mode: "cors",
headers: { "Content-type": "application/json", "X-API-KEY": API_KEY },
}).then((r) => r.json())
```
## Test CORS for POST
Example: Run below in Safari dev console while on `https://dash.cloudflare.com`
```js
const WORKER_URL = "https://foo-worker.workers.dev"
const API_KEY = "SECRET"
await fetch(WORKER_URL + "/foo", {
method: "POST",
mode: "cors",
body: JSON.stringify({ foo: "bar" }),
headers: {
"Content-type": "application/json",
"X-API-KEY": API_KEY,
},
}).then((r) => r.json())
```