{"id":18798396,"url":"https://github.com/cdnjs/api-server","last_synced_at":"2025-04-05T14:07:59.143Z","repository":{"id":39925446,"uuid":"254844386","full_name":"cdnjs/api-server","owner":"cdnjs","description":"📡 API server for api.cdnjs.com - The #1 free and open source CDN built to make life easier for developers. ","archived":false,"fork":false,"pushed_at":"2024-10-28T16:58:10.000Z","size":7038,"stargazers_count":89,"open_issues_count":5,"forks_count":38,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-30T00:55:22.613Z","etag":null,"topics":["api","api-server","cdn","cdnjs","cdnjs-api","cloudflare-worker","cloudflare-workers","hacktoberfest","javascript","wrangler-cli"],"latest_commit_sha":null,"homepage":"https://api.cdnjs.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cdnjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["MattIPv4"],"open_collective":"cdnjs","patreon":"cdnjs"}},"created_at":"2020-04-11T10:33:10.000Z","updated_at":"2024-10-28T16:46:49.000Z","dependencies_parsed_at":"2023-02-15T18:30:54.199Z","dependency_job_id":"cb96f2a3-52d4-425c-9f76-41d8166293fa","html_url":"https://github.com/cdnjs/api-server","commit_stats":{"total_commits":133,"total_committers":6,"mean_commits":"22.166666666666668","dds":"0.24060150375939848","last_synced_commit":"3e3a3af995d7de07db558eceb48416f9e442f952"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdnjs%2Fapi-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdnjs%2Fapi-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdnjs%2Fapi-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdnjs%2Fapi-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdnjs","download_url":"https://codeload.github.com/cdnjs/api-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345853,"owners_count":20924102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-server","cdn","cdnjs","cdnjs-api","cloudflare-worker","cloudflare-workers","hacktoberfest","javascript","wrangler-cli"],"created_at":"2024-11-07T22:11:50.310Z","updated_at":"2025-04-05T14:07:59.125Z","avatar_url":"https://github.com/cdnjs.png","language":"JavaScript","funding_links":["https://github.com/sponsors/MattIPv4","https://opencollective.com/cdnjs","https://patreon.com/cdnjs"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n    \u003ca href=\"https://cdnjs.com\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/cdnjs/brand/master/logo/standard/dark-512.png\" width=\"175px\" alt=\"\u003c cdnjs \u003e\"\u003e\u003c/a\u003e\n\u003c/h1\u003e\n\n\u003ch3 align=\"center\"\u003eThe #1 free and open source CDN built to make life easier for developers.\u003c/h3\u003e\n\n---\n\n## cdnjs API Server\n\nLooking for the documentation on our API?\n\n\u003e [cdnjs API docs](https://cdnjs.com/api)\n\n## Getting Started\n\nThis project uses [Node.js](https://nodejs.org) for development, and is deployed as a\n[Cloudflare Worker](https://workers.cloudflare.com/). Please make sure you have a Node.js version\ninstalled that matches our defined requirement in the [`.nvmrc`](.nvmrc) file for this project.\n\nIncluded with this project is a dependency lock file. This is used to ensure that all installations\nof the project are using the same version of dependencies for consistency. You can install the\ndependencies following this lock file by running:\n\n```sh\nnpm ci\n```\n\nOnce the dependencies are installed, which includes the Wrangler CLI for Cloudflare Workers, you\nneed to create the KV namespace for data caching before the API can be run. This command will ask\nyou to authenticate with a Cloudflare account, so that the Workers KV namespace can be created:\n\n```sh\nwrangler kv:namespace create CACHE --preview\n```\n\nCopy the new `preview_id` returned by the command and replace the existing `id`/preview_id` in\n[`wrangler.toml`](wrangler.toml).\n\nWith the KV namespace setup, the API server is now ready to run in development mode. To start the\nserver in development mode, run:\n\n```sh\nnpm run dev\n```\n\nThis command will ask you to authenticate with a Cloudflare account, so that the worker can be\ndeployed in a development context to Cloudflare's Workers runtime.\n\n## Testing and Linting\n\nOur full set of tests (linting \u0026 a mocha+chai test suite using Miniflare to run the worker locally)\ncan be run at any time with:\n\n```sh\nnpm test\n```\n\n### Linting\n\nIncluded in this repository are an [eslint config file](.eslintrc.cjs) as well as an\n[editorconfig file](.editorconfig) to help with ensuring a consistent style in the codebase for the\nAPI server.\n\nTo help enforce this, we use both eslint and echint in our testing. To run eslint at any time, which\nchecks the code style of any JavaScript, you can use:\n\n```sh\nnpm run test:eslint\n```\n\neslint also provides automatic fixing capabilities, these can be run against the codebase with:\n\n```sh\nnpm run test:eslint:fix\n```\n\nThe more generic rules defined in the [editorconfig file](.editorconfig) apply to all files in the\nrepository and this is enforced by echint, which can be run at any time with:\n\n```sh\nnpm run test:echint\n```\n\n### Testing\n\nThis project uses Mocha and Chai (http) to test the API server, along with Miniflare to run the\nWorker itself in a simulated Cloudflare Workers runtime. The tests attempt to validate every\nroute on the API to ensure that no breaking changes have been made, though there is no promise that\nthis is perfect, a human should always review changes!\n\nThe mocha test suite can be run at any time with the following command (it will build the worker\nusing Wrangler, and then run it with Miniflare during the Mocha+Chai test suite):\n\n```sh\nnpm run test:mocha\n```\n\n## Error Logging\n\nWe use Sentry to handle our error logging. To enable Sentry in the API server, set the `SENTRY_DSN`\nenvironment variable in the [Wrangler config file](wrangler.toml) for the appropriate environment to\na valid DSN URL from Sentry. The `SENTRY_RELEASE` environment variable can also be set to identify a\nspecific release of the worker (our GitHub Actions workflows for deployments set this to the current\ncommit hash).\n\nAlongside the normal error reporting that Sentry provides in the worker, we also fire out custom\nerror events for certain issues to help with improving data consistency across cdnjs:\n\n- `Missing SRI entry` is fired if there is no SRI hash for a file\n- `Bad entry in Algolia data` is fired if an entry in Algolia is falsey, or if its name is falsey\n- `Bad entry in packages data` is fired if a package is falsey, or if its `name`/`version` is falsey\n\n## Deployment\n\nAs this API server is written as a Cloudflare Worker, you can deploy it using the Wrangler CLI. This\ncan be done manually, but this repository uses [GitHub Actions](.github/workflows) to handle\ndeploying to staging (api.cdnjs.dev) and production (api.cdnjs.com) based on commits to the\nstaging/production branches, automatically handling not only deploying the worker but also creating\na Sentry release with full source maps.\n\nBefore deploying, ensure that you generate the required KV namespace for the environment you are\ndeploying to and update [`wrangler.toml`](wrangler.toml) to use the correct ID:\n\n```sh\nwrangler kv:namespace create CACHE --env=staging\n# or\nwrangler kv:namespace create CACHE --env=production\n```\n\nTo deploy to staging (assuming you have write access to this repository), run `make deploy-staging`.\nThis will force-push your latest local commit to the staging branch, which will trigger GitHub\nActions to run and deploy your worker to Cloudflare Workers.\n\nSimilarly, for a production deployment, run `make deploy-production`. This will force-push to the\nproduction branch instead, and trigger the production GitHub Actions workflow.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdnjs%2Fapi-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdnjs%2Fapi-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdnjs%2Fapi-server/lists"}