checked-fetch.js 834 B

123456789101112131415161718192021222324252627282930
  1. const urls = new Set();
  2. function checkURL(request, init) {
  3. const url =
  4. request instanceof URL
  5. ? request
  6. : new URL(
  7. (typeof request === "string"
  8. ? new Request(request, init)
  9. : request
  10. ).url
  11. );
  12. if (url.port && url.port !== "443" && url.protocol === "https:") {
  13. if (!urls.has(url.toString())) {
  14. urls.add(url.toString());
  15. console.warn(
  16. `WARNING: known issue with \`fetch()\` requests to custom HTTPS ports in published Workers:\n` +
  17. ` - ${url.toString()} - the custom port will be ignored when the Worker is published using the \`wrangler deploy\` command.\n`
  18. );
  19. }
  20. }
  21. }
  22. globalThis.fetch = new Proxy(globalThis.fetch, {
  23. apply(target, thisArg, argArray) {
  24. const [request, init] = argArray;
  25. checkURL(request, init);
  26. return Reflect.apply(target, thisArg, argArray);
  27. },
  28. });