INTEGRITY Dokumentace

Custom Domain with Images

Pokud chcete rychle začít, klikněte na tlačítko níže.

Deploy to Cloudflare

Tím se vytvoří repozitář ve vašem účtu GitHub a aplikace se nasadí na Cloudflare Workers.

Chcete-li zobrazovat obrázky z vlastní domény:

  1. V dashboardu Cloudflare přejděte na Workers & Pages stránce.

    Přejděte na Workers & Pages ↗
  2. Vyberte Vytvoření aplikace > Workers > Create Worker a vytvořte svého Workera.

  3. Ve svém Workeru vyberte Quick edit a vložte následující kód.

export default {
	async fetch(request) {
		// You can find this in the dashboard, it should look something like this: ZWd9g1K7eljCn_KDTu_MWA
		const accountHash = "";

		const { pathname } = new URL(request.url);

		// A request to something like cdn.example.com/83eb7b2-5392-4565-b69e-aff66acddd00/public
		// will fetch "https://imagedelivery.net/<accountHash>/83eb7b2-5392-4565-b69e-aff66acddd00/public"

		return fetch(`https://imagedelivery.net/${accountHash}${pathname}`);
	},
};
export default {
	async fetch(request): Promise<Response> {
		// You can find this in the dashboard, it should look something like this: ZWd9g1K7eljCn_KDTu_MWA
		const accountHash = "";

		const { pathname } = new URL(request.url);

		// A request to something like cdn.example.com/83eb7b2-5392-4565-b69e-aff66acddd00/public
		// will fetch "https://imagedelivery.net/<accountHash>/83eb7b2-5392-4565-b69e-aff66acddd00/public"

		return fetch(`https://imagedelivery.net/${accountHash}${pathname}`);
	},
} satisfies ExportedHandler;
import { Hono } from 'hono';

interface Env {
  // You can store your account hash as a binding variable
  ACCOUNT_HASH?: string;
}

const app = new Hono<{ Bindings: Env }>();

app.get('*', async (c) => {
  // You can find this in the dashboard, it should look something like this: ZWd9g1K7eljCn_KDTu_MWA
  // Either get it from environment or hardcode it here
  const accountHash = c.env.ACCOUNT_HASH || "";

  const url = new URL(c.req.url);

  // A request to something like cdn.example.com/83eb7b2-5392-4565-b69e-aff66acddd00/public
  // will fetch "https://imagedelivery.net/<accountHash>/83eb7b2-5392-4565-b69e-aff66acddd00/public"

  return fetch(`https://imagedelivery.net/${accountHash}${url.pathname}`);
});

export default app;
from workers import WorkerEntrypoint
from js import URL, fetch

class Default(WorkerEntrypoint):
    async def fetch(self, request):
        # You can find this in the dashboard, it should look something like this: ZWd9g1K7eljCn_KDTu_MWA
        account_hash = ""
        url = URL.new(request.url)

        # A request to something like cdn.example.com/83eb7b2-5392-4565-b69e-aff66acddd00/public
        # will fetch "https://imagedelivery.net/<accountHash>/83eb7b2-5392-4565-b69e-aff66acddd00/public"
        return fetch(f'https://imagedelivery.net/{account_hash}{url.pathname}')

Obrázky z vlastní domény můžete zobrazovat také pomocí cdn-cgi/imagedelivery prefixovou cestu, která se používá jako cesta pro spuštění cdn-cgi proxy pro obrázky.

Níže je uveden příklad, kde je hostname doménou proxovanou přes Cloudflare ve stejném účtu jako Image, za níž následuje prefixová cesta a obrázek <ACCOUNT_HASH>, <IMAGE_ID> a <VARIANT_NAME> které najdete v Obrázky na dashboardu Cloudflare.

https://example.com/cdn-cgi/imagedelivery/<ACCOUNT_HASH>/<IMAGE_ID>/<VARIANT_NAME>