Tuesday, 25 April 2017

How to generate an image in nodejs and sent it to fontend?

fontend:

var img = new Image();
img.onload = function() {
    console.log('done');
};
img.onerror = function() {
    console.log('error'); // trigger
};
img.src = 'http://localhost: 3000?test.gif';

backend:

const express = require('express');
const app = express();

app.get('/grabber.gif', (req, res) => {
    res.type('gif');
    res.send(new Buffer(1));
});

const server = app.listen(3000, () => {
    console.log(`listen at http://localhost:${3000}`);
});

Is it because the headers??

If it's true, and how can I rewrite the headers?

Or is it the wrong way to generate an image?



via Sid Kwok

No comments:

Post a Comment