S
S
SOjuD2019-09-20 13:27:48
Node.js
SOjuD, 2019-09-20 13:27:48

Why is node.js server not serving svg correctly?

Here is part of the code

let server = http.createServer((req, res) => {

    if(req.url.match(/.svg$/)){

        let data = fs.createReadStream(path.join(__dirname, 'public', req.url));
        res.writeHead(200, {
            'Conten-Type' : 'image/svg+xml'
    })
        data.pipe(res);

    }else{
        handleError(404, new Error('Страница не найдена'), res);
    }
            

});
server.listen('4000', () => {console.log('Server run')});

I thought that the problem was in the 'transfer-encoding' : 'chunck' header, removed it but it didn't help, the conten type is set to svg+xml, but in the developer tools in the network tab in the type text/plain column
5d84a9a443cd0714690154.png
5d84a967ea5bb907298587.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question