summaryrefslogtreecommitdiff
path: root/node_modules/wrangler/templates/pages-dev-pipeline.ts
blob: 27fa4e140c6b851416866f71df20190e56d1ffe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// @ts-ignore entry point will get replaced
import worker from "__ENTRY_POINT__";
// @ts-ignore entry point will get replaced
export * from "__ENTRY_POINT__";
import { isRoutingRuleMatch } from "./pages-dev-util";

// @ts-ignore routes are injected
const routes = __ROUTES__;

export default <ExportedHandler<{ ASSETS: Fetcher }>>{
	fetch(request, env, context) {
		const { pathname } = new URL(request.url);

		for (const exclude of routes.exclude) {
			if (isRoutingRuleMatch(pathname, exclude)) {
				return env.ASSETS.fetch(request);
			}
		}

		for (const include of routes.include) {
			if (isRoutingRuleMatch(pathname, include)) {
				if (worker.fetch === undefined) {
					throw new TypeError("Entry point missing `fetch` handler");
				}
				return worker.fetch(request, env, context);
			}
		}

		return env.ASSETS.fetch(request);
	},
};