Chrome Extension

CORS Headers in Nodejs

app.use((req,res,next)=>{
    res.header('Access-Control-Allow-Origin','*');
    res.header(
        'Access-Control-Allow-Header',
        'Origin,X-Resquested-With,Content-Type,Accept,Authorization'
        );
    if(req.method === 'OPTIONS'){
        res.header(
            'Access-Control-Allow-Methods',
            'GET,POST,PUT,PATCH,DELETE'
            );
        return res.status(200).json({});
    }
    next();
});

This is cors headers management snippet built in Nodejs

Search history ×