{"id":23962814,"url":"https://github.com/wileylabs/web-redirects-cli","last_synced_at":"2025-04-13T11:32:44.023Z","repository":{"id":37085743,"uuid":"291822570","full_name":"WileyLabs/web-redirects-cli","owner":"WileyLabs","description":"Managing HTTP(S) redirects via YAML (or JSON) docs","archived":false,"fork":false,"pushed_at":"2025-02-21T08:15:26.000Z","size":1496,"stargazers_count":3,"open_issues_count":7,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-27T02:43:23.147Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/WileyLabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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}},"created_at":"2020-08-31T20:54:45.000Z","updated_at":"2024-12-18T16:22:32.000Z","dependencies_parsed_at":"2023-02-13T03:00:42.922Z","dependency_job_id":"c36f7aea-53f0-4714-978f-a5b0838d0bc3","html_url":"https://github.com/WileyLabs/web-redirects-cli","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WileyLabs%2Fweb-redirects-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WileyLabs%2Fweb-redirects-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WileyLabs%2Fweb-redirects-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WileyLabs%2Fweb-redirects-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WileyLabs","download_url":"https://codeload.github.com/WileyLabs/web-redirects-cli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248705760,"owners_count":21148586,"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":[],"created_at":"2025-01-06T20:56:37.240Z","updated_at":"2025-04-13T11:32:43.998Z","avatar_url":"https://github.com/WileyLabs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Web Redirects\n\nManaging a wide range of Web (HTTP and HTTPS) redirects can be challenging,\nconfusing, and cumbersome. This project aims to provide a descriptive approach\nto defining what redirects should exist per domain name.\n\n## Usage\n\nThis project is currently aimed at coordinating descriptive redirect documents\n(available in JSON or YAML) and converting them into Cloudflare Page Rules\n(and eventually Cloudflare Worker-backed routers).\n\nStep one (consequently) is to [get a Cloudflare API Token setup for your\naccount](https://support.cloudflare.com/hc/en-us/articles/200167836-Managing-API-Tokens-and-Keys#12345680) with \"Read all resources\" permission. Unless you are a \"Super Administrator\"\nyou will likely have to remove some of those perset permissions as your account\ndoes not have permission to read all resources. Note: The longer term goal is\nto also request edit level permissions (to manage/populate redirects) and to\nonly request the specific permissions needed to make these transactions.\n\nOnce you have that API Token, set it as an environment variable (and store it\nsomewhere safely that you can rereference!):\n\n```sh\n$ export WR_CLOUDFLARE_TOKEN=r98...z4\n```\nNote: You can also pass this token in as a command line parameter\n(i.e. `--cloudflareToken`) if you'd prefer.\n\n\nNext install the script, and run it to see the help information:\n```sh\n$ npm i\n$ redirects -h\nredirects \u003ccmd\u003e [args]\n\nCommands:\n  redirects zones             List zones in current Cloudflare account\n  redirects show [domain]     Show current redirects for [domain]\n  redirects check [domain]    Check a [domain]'s settings with [configDir]'s\n                              default configuration (`.settings.yaml`)\n  redirects compare [domain]  Compare [configDir]'s local redirect descriptions\n                              for [domain] with Cloudflare's\n```\n\nCurrently, all the comands require the `--cloudflareToken` which can also be\nset as an environment variable: `WR_CLOUDFLARE_TOKEN`.\n\nAdditionally, the redirect descriptions are managed in a single directory who's\npath can be set using the `--configDir` or `WR_CONFIG_DIR` environment\nvariable. It does default to `.`, so if you're running `redirects` in your\nconfig/redirects folder, then you can avoid setting it.\n\nAlternatively, you can create a `.env` file in the directory from which you\nplan to run the `redirects` command.\n\nFor example:\n```sh\n# .env\nWR_CLOUDFLARE_TOKEN=\"H32...23H\"\nWR_ACCOUNT_ID=\"...\"\nWR_WORKER_KV_NAMESPACE=\"...\"\nWR_CONFIG_DIR=\"redirects/\"\n```\n\n## Settings and Redirects Directory\n\nCreate a directory (typically `domains/` or `redirects/`) anywhere you'd like\nto track such things. To get all your redirects on the same foundation, add a\n`.settings.yaml` file to that directory. Here's a starter (with some tweaks to\nCloudflare's defaults):\n```yaml\n---\n# Standard settings for all redirect zones\nalways_use_https: \"on\"\nipv6: \"on\"\nmin_tls_version: \"1.2\"\nsecurity_header:\n  strict_transport_security:\n    enabled: true\n    max_age: 0\n    include_subdomains: true\n    preload: true\n    nosniff: true\nssl: \"full\"\n```\n\nEach key maps to a [Cloudflare Zone\nSetting](https://api.cloudflare.com/#zone-settings-properties).\n\nThe `check` command will explain where things differ between the\n`.settings.yaml` contents, and the currently selected zone.\n\nOnce that's created, you can add additional \"Redirect Documents\" to the\ndirectory--one per zone name (typically the apex domain for your redirects).\n\n## Write a Redirect Document\n\nNOTE: this is a description of where this project is headed...not where it is\n...yet.\n\nFirst, create a directory to hold your redirects.\n\nThen, within that directory, add a JSON file per zone/site/domain which you\nwill (or have) setup in Cloudflare and use the following format:\n\n```json\n{\n  \"cloudflare:id\": \"z14...r72\",\n  \"fallthrough\": false,\n  \"name\": \"example.com\",\n  \"redirects\": [\n    {\n      \"from\": \"/(.*)\",\n      \"to\": \"https://example.org/$1\",\n    },\n    {\n      \"base\": \"www.example.com\",\n      \"from\": \"/only-on-www\",\n      \"to\": \"https://example.org/www-was-here\",\n      \"status\": 301,\n      \"caseSensitive\": false,\n      \"includeParams\": false\n    }\n  ]\n}\n```\n\nThe `fallthrough` key, if set to true - allows requests that are not redirected \nto continue processing (e.g. serve content from a defined DNS entry) - rather\nthan the default behaviour (`\"fallthrough\": false`) which will return a 404 response.\n\nThe `redirects.base` key, if absent is presumed to be `*${name}/*` when\ncreating Page Rule based redirects.\n\nThe `redirects.status` key, if not specified has a default value of `301`.\n\nThe `redirects.caseSensitive` key, if not specified has default value of `false`.\n\nThe `redirects.includeParams` key, if not specified has default value of `false`.\nBy default only the request path will be matched. If `\"includeParams\": true` then\nthe request query string will be included in the redirect matching.\n\n## Deployments (Using Wrangler)\n\nWith the ongoing development of the worker script, and the inclusion of NodeJS dependencies\nit has been necessary to use Wrangler to deploy changes. As a result the script should be deployed\nas described here.\n\n### Wrangler Installation\n\nAs Wrangler is included as a dependency for this package - you can use `npx` to run the \nWrangler commands needed to deploy the `web-redirects-cli` worker.\n\n(If you want to install Wrangler globally, you can find instructions here: \nhttps://developers.cloudflare.com/workers/wrangler/install-and-update/)\n\n```\n\u003e npm i\n\u003e npx wrangler -v\n```\n\n### Wrangler Configuration (wrangler.toml)\n\nThe `wrangler.toml` file should be the 'source of truth' for the Worker configuration.\nThough we won't store worker route/custom domain information here - that will be managed \nvia the `web-redirects-cli` CLI and redirects YAML files.\n\nFind more details here: https://developers.cloudflare.com/workers/wrangler/configuration/\n\n### Deploying Changes\n\nTo deploy the worker to production or non-production you will need to login via `wrangler`\n\n```\n\u003e npx wrangler login \n...\n```\n\nThis will redirect you to your default browser - to login to Cloudflare and grant authorization to `wrangler`.\nOnce logged in you can check your current access using the `whoami` sub-command.\n\n```\n\u003e npx wrangler whoami\n...\n```\n\nIf required, you can log out after completing a deployment.\n\n```\n\u003e npx wrangler logout\n```\n\nBy default Wrangler will publish Worker script changes using a non-production service name\n(the default configuration defined in `wrangler.toml`). To deploy using the production service name, the environment\nmust be specified:\n\nDefault (non-prod)\n```\n\u003e npx wrangler deploy\n```\n\nDeploy to Production\n```\n\u003e npx wrangler deploy --env production\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwileylabs%2Fweb-redirects-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwileylabs%2Fweb-redirects-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwileylabs%2Fweb-redirects-cli/lists"}