If you want to get started quickly, click on the button below.

[![Deploy to Cloudflare](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/docs-examples/tree/main/workers/respond-with-another-site)

This creates a repository in your GitHub account and deploys the application to Cloudflare Workers.

* JavaScript

  ```js
  export default {
    async fetch(request) {
      async function MethodNotAllowed(request) {
        return new Response(`Method ${request.method} not allowed.`, {
          status: 405,
          headers: {
            Allow: "GET",
          },
        });
      }
      // Only GET requests work with this proxy.
      if (request.method !== "GET") return MethodNotAllowed(request);
      return fetch(`https://example.com`);
    },
  };
  ```

  [Run Worker in Playground](https://workers.cloudflare.com/playground#LYVwNgLglgDghgJwgegGYHsHALQBM4RwDcABAEbogB2+CAngLzbPYZb6HbW5QDGU2AAwB2YQFZhARgAskyWICcggFwsWbYBzhcafASPFTZ8pQFgAUAGF0VCAFNb2ACJQAzjHSuo0G8pIa8AmISKjhgOwYAIigaOwAPADoAK1dI0lQoMAcwiOjYxJTIi2tbBwhsABU6GDs-OBgYMD4CKBtkJLgANzhXXgRYCABqYHRccDsLC3iPJBJcO1Q4cAgSAG9zEhIeuipefzsIXgALAAoEOwBHEDtXCABKNY3NrdcdvdRqXh8qEgBZA6OowAcugIABBMBgdAAdzsuDOl2utwe62ez3OEBACB+VDs0JIACUbh4qK47CcAAb-CCA3AkAAkq3OVxuEAS4RpowAviFQVtITC4QkKQAaR5otG3AggVx+aSCMQip4SkhHOxweYIWXilXPCFQ6F+SIAcQAohVIkrdSQuVaJVy7kRlTbnchkCQAPJUMB0EhmiokZlIiCuEjQzAAazD3iOJBpbhIMAQ6DidASzqgqBICJZt3ZANGJAAhAwGCQTebIg8MViftTaSDwQLYfCg6zHc6a9j9odThSjhAIDBZW74mFGnYErx0MAKR3NrbzFyiBY1MwNFodDx+EJRBIZHJFIJijZ7I4XO5PN5WlQ-AEtKRQuEohyNUE0v5Mtln5EyFCyEUVinmUlTVLUWwNE0vAtG0KQ2JM5irJEwBwDEAD6IxjFkkTKHk8wFKkXKrmuG5BFuei7oYB4mIIzBAA)

* TypeScript

  ```ts
  export default {
    async fetch(request): Promise<Response> {
      async function MethodNotAllowed(request) {
        return new Response(`Method ${request.method} not allowed.`, {
          status: 405,
          headers: {
            Allow: "GET",
          },
        });
      }
      // Only GET requests work with this proxy.
      if (request.method !== "GET") return MethodNotAllowed(request);
      return fetch(`https://example.com`);
    },
  } satisfies ExportedHandler;
  ```

* Python

  ```py
  from workers import Response, fetch


  def on_fetch(request):
      def method_not_allowed(request):
          msg = f'Method {request.method} not allowed.'
          headers = {"Allow": "GET"}
          return Response(msg, headers=headers, status=405)


      # Only GET requests work with this proxy.
      if request.method != "GET":
          return method_not_allowed(request)


      return fetch("https://example.com")
  ```
