pages-dev-pipeline.ts 848 B

12345678910111213141516171819202122232425262728293031
  1. // @ts-ignore entry point will get replaced
  2. import worker from "__ENTRY_POINT__";
  3. // @ts-ignore entry point will get replaced
  4. export * from "__ENTRY_POINT__";
  5. import { isRoutingRuleMatch } from "./pages-dev-util";
  6. // @ts-ignore routes are injected
  7. const routes = __ROUTES__;
  8. export default <ExportedHandler<{ ASSETS: Fetcher }>>{
  9. fetch(request, env, context) {
  10. const { pathname } = new URL(request.url);
  11. for (const exclude of routes.exclude) {
  12. if (isRoutingRuleMatch(pathname, exclude)) {
  13. return env.ASSETS.fetch(request);
  14. }
  15. }
  16. for (const include of routes.include) {
  17. if (isRoutingRuleMatch(pathname, include)) {
  18. if (worker.fetch === undefined) {
  19. throw new TypeError("Entry point missing `fetch` handler");
  20. }
  21. return worker.fetch(request, env, context);
  22. }
  23. }
  24. return env.ASSETS.fetch(request);
  25. },
  26. };