To solve error 'No Access-Control-Allow-Origin'
So I tried to search for Access-Control-Allow-Origin for Node.js, but I could only see those using Express.js api.
The warning looks like very simple: add header 'Access-Control-Allow-Origin' to the response.
Origin http://localhost is not allowed by Access-Control-Allow-Origin
Like the question above, I could also see many answers have app.use or res.header but:
- I don't know where the app. comes from
res.header doesn't work for
http.createServer(function (req, res){ "Something" });
Also, I tried
res.writeHead(200, {'Access-Control-Allow-Origin': '*',
'Content-Type': 'text/html','Content-Length':data.length});
But doesn't work.
I know this problem can be solved on the client side, like security off option for chrome or add on. But I want my server gives service on any client so that the users don't need to do any setting on it.