Express JavaScript
一个用于 Express 的 JavaScript 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。
Express JavaScript
import express from 'express';
const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');
const app = express();
app.get('/pixel.gif', (req, res) => {
res.set('Cache-Control', 'no-store');
res.type('gif').send(GIF);
});
app.listen(8080);
我们运行了此代码片段,并比对了它返回的字节。
验证
curl -sI http://localhost:8080/pixel.gif
更多 JavaScript 示例
- Fastify
- Node.js standard library (node:http)
- Koa
- 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)