跳转到内容
搜索文档

返回其他站点内容

用另一个网站(本示例为 example.com)的响应来回复 Worker 请求。 (example.com in this example).

最后更新 查看 MarkdownAgent 设置

如需快速上手,请点击下方按钮。

Deploy to Cloudflare

这会在你的 GitHub 账户中创建仓库,并将应用部署到 Cloudflare Workers。

export default {
  async fetch(request) {
    function MethodNotAllowed(request) {
      return new Response(`Method ${request.method} not allowed.`, {
        status: 405,
        headers: {
          Allow: "GET",
        },
      });
    }
    // 此代理仅支持 GET 请求。
    if (request.method !== "GET") return MethodNotAllowed(request);
    return fetch(`https://example.com`);
  },
};
export default {
	async fetch(request): Promise<Response> {
		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;
from workers import WorkerEntrypoint, Response, fetch

class Default(WorkerEntrypoint):
    def fetch(self, 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")

这篇文档对您有帮助吗?