Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ jobs:

- name: Run Web Tests (deployed)
id: web-tests-deployed
if: github.ref_name == 'staging'
run: npm run test:web
env:
PLAYWRIGHT_EXTERNAL_WEB_URL: ${{ github.ref_name == 'production' && 'https://cdnjs.com' || 'https://cdnjs.dev' }}
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:

- name: Run Web Tests
id: web-tests
if: matrix.worker == 'staging'
run: npm run test:web
env:
PLAYWRIGHT_EXTERNAL_WEB_URL: ${{ matrix.worker == 'production' && 'https://cdnjs.com' || 'https://cdnjs.dev' }}
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

---

## cdnjs API Server
## cdnjs API + Website Worker

Looking for the documentation on our API?

Expand Down Expand Up @@ -38,9 +38,9 @@ This command will run the worker entirely locally, and you can access the API at

### Website React Output

The same API server worker also powers the [cdnjs.com](https://cdnjs.com) website, returning
The same Cloudflare worker also powers the [cdnjs.com](https://cdnjs.com) website, returning
rendered React responses. This done by setting the `WEBSITE_BASE` Worker environment variable, which
will cause the API server to return HTML instead of JSON when a request has a matching base URL.
will cause the worker to return HTML instead of JSON when a request has a matching base URL.
While the worker cannot be served from multiple base URLs in development mode, you can run the
worker with the `WEBSITE_BASE` environment variable set to `http://localhost:8787` to test locally:

Expand Down Expand Up @@ -114,7 +114,7 @@ npm run test:web

### Type-Checking

The API server is written in TypeScript, and the types are checked as part of the test suite. If you
The worker is written in TypeScript, and the types are checked as part of the test suite. If you
want to run the type-checking separately, you can use:

```sh
Expand All @@ -132,7 +132,7 @@ npm run prepare:types
### Linting

Included in this repository is an [eslint config file](eslint.config.js) to help with ensuring a
consistent style and safely written codebase for the API server. To run eslint at any time, which
consistent style and safely written codebase for the worker. To run eslint at any time, which
checks all the TypeScript files, you can use:

```sh
Expand Down Expand Up @@ -164,19 +164,19 @@ npm run format:fix

## Error Logging

We use Sentry to handle our error logging. To enable Sentry in the API server, set the `SENTRY_DSN`
environment variable in the [Wrangler config file](wrangler.jsonc) for the appropriate environment to
a valid DSN URL from Sentry. The `SENTRY_RELEASE` environment variable can also be set to identify a
specific release of the worker (our GitHub Actions workflows for deployments set this to the current
commit hash).
We use Sentry to handle our error logging. To enable Sentry in the worker, set the `SENTRY_DSN`
environment variable in the [Wrangler config file](wrangler.jsonc) for the appropriate environment
to a valid DSN URL from Sentry. The `SENTRY_RELEASE` environment variable can also be set to
identify a specific release of the worker (our GitHub Actions workflows for deployments set this to
the current commit hash).

## Deployment

As this API server is written as a Cloudflare Worker, you can deploy it using the Wrangler CLI. This
can be done manually, but this repository uses [GitHub Actions](.github/workflows) to handle
deploying to staging (api.cdnjs.dev) and production (api.cdnjs.com) based on commits to the
staging/production branches, automatically handling not only deploying the worker but also creating
a Sentry release with full source maps.
As this API + web server is written as a Cloudflare Worker, it can be deployed via the Wrangler CLI.
This can be done manually, but this repository uses [GitHub Actions](.github/workflows) to handle
deploying to staging (`cdnjs.dev`) and production (`cdnjs.com`) based on commits to the
`staging`/`production` branches, automatically handling not only deploying the worker but also
creating a Sentry release with full source maps.

Before deploying, ensure that you generate the required KV namespace for the environment you are
deploying to and update [`wrangler.jsonc`](wrangler.jsonc) to use the correct ID:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "api-server",
"version": "1.0.0",
"description": "The new API server for api.cdnjs.com",
"description": "The Cloudflare worker powering cdnjs.com + api.cdnjs.com",
"private": true,
"type": "module",
"main": "src/index.ts",
Expand Down
14 changes: 10 additions & 4 deletions wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,16 @@
},
},
"production": {
"route": {
"pattern": "api.cdnjs.com/*",
"zone_name": "cdnjs.com",
},
"routes": [
{
"pattern": "api.cdnjs.com/*",
"zone_name": "cdnjs.com",
},
{
"pattern": "cdnjs.com/*",
"zone_name": "cdnjs.com",
},
],
"kv_namespaces": [
{
"binding": "CACHE",
Expand Down
Loading