I have tried to use nginx, but I don’t know nginx at all. After configuring it for a long time, I still can’t figure it out. Is there any other simple method that can easily solve the cross-domain problem?
怪我咯2017-06-28 09:25:00
I don’t understand the role of your middle layer. Anyway, to solve the cross-domain problem, just add a field to the response header: Access-Control-Allow-Origin: *
As for how to add it, you can use res.writeHead
You can add it this way, or any other way. As long as you can see this header field in the final response returned to the browserok
某草草2017-06-28 09:25:00
//Configure node cross-domain
app.all('*', (req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
res.header('Access-Control-Allow-Methods', "PUT, POST, GET, DELETE, OPTIONS");
res.header('Content-Type', 'application/json;charset=utf-8');
next();
})