Lahat ng language at framework
Koa JavaScript
Isang JavaScript snippet para sa Koa na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.
Koa JavaScript
import Koa from 'koa';
import Router from '@koa/router';
const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');
const app = new Koa();
const router = new Router();
router.get('/pixel.gif', (ctx) => {
ctx.type = 'image/gif';
ctx.set('Cache-Control', 'no-store');
ctx.body = GIF;
});
app.use(router.routes()).listen(8080);
Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.
Suriin
curl -sI http://localhost:8080/pixel.gif
Iba pa sa JavaScript
- Fastify
- Express
- Node.js standard library (node:http)
- hapi
- AWS Lambda (Node.js)
- AWS Lambda@Edge (CloudFront)
- Google Cloud Run functions (Node.js)
- Firebase Cloud Functions + Hosting
- Azure Functions (Node.js v4 model)
- Fastly Compute (JavaScript)
- nginx JavaScript (njs)
- Node.js one-liner
- Bun one-liner
- React component (JSX)