javascript - How to solve cross-domain problems for the middle layer in node
大家讲道理
大家讲道理 2017-06-28 09:23:00
0
2
824

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?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
刘奇

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

某草草

//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();
}) 
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template