emptygif
Lingua: Italiano

Tutti i linguaggi e framework

Node.js standard library (node:http) JavaScript

Uno snippet JavaScript per Node.js standard library (node:http) che risponde alle richieste a /pixel.gif con la GIF vuota, decodificata una sola volta all'avvio.

Node.js standard library (node:http) JavaScript

File
server.mjs
Esegui
node server.mjs
import { createServer } from 'node:http';

const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');

createServer((req, res) => {
  const { pathname } = new URL(req.url, 'http://localhost');
  if (req.method !== 'GET' || pathname !== '/pixel.gif') {
    res.writeHead(404).end();
    return;
  }
  res.writeHead(200, {
    'Content-Type': 'image/gif',
    'Content-Length': GIF.length,
    'Cache-Control': 'no-store',
  });
  res.end(GIF);
}).listen(8080);

Abbiamo eseguito questo snippet e confrontato i byte che ha restituito.

Verifica

curl -sI http://localhost:8080/pixel.gif

Sito ufficiale: Node.js standard library (node:http)

Altro in JavaScript