Deno Deploy (deno serve) TypeScript
適用於 Deno Deploy (deno serve) 的 TypeScript 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。
Deno Deploy (deno serve) TypeScript
import { decodeBase64 } from 'jsr:@std/encoding/base64';
const GIF = decodeBase64('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
export default {
fetch(req) {
if (new URL(req.url).pathname !== '/pixel.gif') {
return new Response('Not Found', { status: 404 });
}
return new Response(GIF, {
headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
});
},
} satisfies Deno.ServeDefaultExport;
我們執行了這段程式碼,並比對了它回傳的位元組。
驗證
curl -sI http://localhost:8080/pixel.gif
官方網站: Deno Deploy (deno serve)