I need to get the value x-api-key that send me in the header in my end point with method get. the code in my end point is the next.in my localhost work fine. but in the server not work. the error is
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
router.get('/orders',async (req, res, next) => {
const apikey = req.header('x-api-key')
try {
const customer = await Customer.find({apikey:apikey})
const orders = await Order.find({ customer: ObjectId(customer[0]._id)})
res.status(200).json(orders)
} catch (error) {
res.status(400).json({"message":"Error"})
next(error)
}
})
I've seen other posible solutions but I cant find the solution.