Skip to content

Instantly share code, notes, and snippets.

@rjrodger rjrodger/servegif.js
Created Jan 26, 2011

Embed
What would you like to do?
node.js: serve a 1x1 gif
var connect = require('connect')
var imgdata = [
0x47,0x49, 0x46,0x38, 0x39,0x61, 0x01,0x00, 0x01,0x00, 0x80,0x00, 0x00,0xFF, 0xFF,0xFF,
0x00,0x00, 0x00,0x21, 0xf9,0x04, 0x04,0x00, 0x00,0x00, 0x00,0x2c, 0x00,0x00, 0x00,0x00,
0x01,0x00, 0x01,0x00, 0x00,0x02, 0x02,0x44, 0x01,0x00, 0x3b
]
var imgbuf = new Buffer(imgdata)
var server = connect.createServer(
connect.router(function(app){
app.get('/the.gif',function(req,res,next){
res.writeHead(200,{
'Content-Type': 'image/gif',
'Content-Length': imgdata.length,
})
res.end(imgbuf)
})
})
)
// serve the gif on http://localhost:4000/the.gif
server.listen(4000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.