express cross-domain settings

app.use(function (req, res, next) {
    res.header('Access-Control-Allow-Origin', 'http://localhost:8081');
    // allowed header type
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
    res.header("Access-Control-Allow-Methods","DELETE,PUT,POST,GET,OPTIONS");
    if (req.method.toLowerCase() == 'options')
        res.send (200); // try to request a quick end to make options
    else
        next();
});

 

 

 
 

Guess you like

Origin www.cnblogs.com/guangzhou11/p/11575315.html