Answer the question
In order to leave comments, you need to log in
How to enable Access-Control-Allow-Origin in json-server?
I have an angular2 frontend and json-server backend . angular2 works on address: localhost:4200 json-server works on address: localhost:3000
The problem is that I don't know how to make json-server give data with header: Access-Control-Allow-Origin: *
This is necessary so that the frontend can get the result of a cross-domain query.
Please tell me how to do it. I don't even understand where the server config is located. I didn't find it in node_modules
Answer the question
In order to leave comments, you need to log in
// ...
server.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
next()
})
// ...
I
myself suffer getApiUser() {
let header = new Headers();
header.append('Content-Type', 'application/json; charset=utf-8');
return this.http.get(this.url).map(res => res.json())
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question