Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gregbrimble/redirects-in-workers
Cloudflare Pages' _redirects file support in Cloudflare Workers
https://github.com/gregbrimble/redirects-in-workers
Last synced: 28 days ago
JSON representation
Cloudflare Pages' _redirects file support in Cloudflare Workers
- Host: GitHub
- URL: https://github.com/gregbrimble/redirects-in-workers
- Owner: GregBrimble
- License: mit
- Created: 2024-09-17T02:15:17.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-09-17T04:45:03.000Z (about 2 months ago)
- Last Synced: 2024-09-18T03:56:18.571Z (about 2 months ago)
- Language: TypeScript
- Size: 57.6 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# redirects-in-workers
Cloudflare Pages' `_redirects` file support in Cloudflare Workers
## Installation
```sh
npm install redirects-in-workers
```## Usage
```toml
# wrangler.tomlrules = [
{ type = "Text", globs = ["**/_redirects"], fallthrough = true }
]
``````js
import { generateRedirectsEvaluator } from "redirects-in-workers";
import redirectsFileContents from "../public/_redirects";
import { WorkerEntrypoint } from "cloudflare:workers";const redirectsEvaluator = generateRedirectsEvaluator(redirectsFileContents);
export default class extends WorkerEntrypoint {
override async fetch(request: Request) {
const redirect = await redirectsEvaluator(request, this.env.ASSETS);
if (redirect) {
return redirect;
}// do other stuff
return new Response("Hello, world!");
}
}
```