Always set Access-Control-Allow-Origin on response
Error responses were not having this set, which obscured the true error from the client.
This commit is contained in:
parent
94521b73bb
commit
18f97b6ec1
|
@ -79,12 +79,16 @@ static id s_executor;
|
|||
NSError *error;
|
||||
NSData *data = [(GCDWebServerDataRequest *)request data];
|
||||
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
|
||||
if (error) {
|
||||
NSLog(@"%@", error);
|
||||
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_UnprocessableEntity underlyingError:error message:@"Invalid RPC request"];
|
||||
GCDWebServerResponse *response;
|
||||
|
||||
if (error || ![json isKindOfClass:[NSDictionary class]]) {
|
||||
NSLog(@"Invalid RPC request - %@", error ?: json);
|
||||
response = [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_UnprocessableEntity underlyingError:error message:@"Invalid RPC request"];
|
||||
}
|
||||
else {
|
||||
response = [GCDWebServerDataResponse responseWithJSONObject:[rpcServer performRequest:request.path args:json]];
|
||||
}
|
||||
|
||||
GCDWebServerDataResponse *response = [GCDWebServerDataResponse responseWithJSONObject:[rpcServer performRequest:request.path args:json]];
|
||||
[response setValue:@"http://localhost:8081" forAdditionalHeader:@"Access-Control-Allow-Origin"];
|
||||
return response;
|
||||
}];
|
||||
|
|
Loading…
Reference in New Issue