I
I
ivandao2019-09-16 18:58:42
Node.js
ivandao, 2019-09-16 18:58:42

Error setting response headers?

There is a module that disables cors

// cors-headers
module.exports = (request, response, next) => {   
    response.set({
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'DELETE,GET,PATCH,POST,PUT',
        'Access-Control-Allow-Headers': 'Content-Type,Authorization,origin,accept'
    });
    next();
};

I use it
const express = require('express');
const corsHeaders = require('./middleware/cors-headers');
const app = express();
app.use(corsHeaders);
// .. app.get(), app.post() ...

When I send a response to the client response.send(data), a warning appears:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
How to treat?

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