Package Exports
- redirects-in-workers
- redirects-in-workers/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (redirects-in-workers) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
redirects-in-workers
Cloudflare Pages' _redirects file support in Cloudflare Workers
Installation
npm install redirects-in-workersUsage
# wrangler.toml
rules = [
{ type = "Text", globs = ["**/_redirects"], fallthrough = true }
]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!");
}
}