Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 968f59a

Browse files
committed
fix: Add response header to allow CORS requests
Since API does not respond with "Access-Control-Allow-Origin" header, the response data are blocked when calling the API from browser. To eliminate this problem, add "Access-Control-Allow-Origin" header to each API response.
1 parent 8553021 commit 968f59a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

accelerator/server.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ int main(int, char const**) {
4444
api_find_transactions_by_tag(&service, req.params["tag"].c_str(),
4545
&json_result);
4646
res.set_header("Content-Type", "application/json");
47+
res.set_header("Access-Control-Allow-Origin", "*");
4748
res << json_result;
4849
});
4950

@@ -65,6 +66,7 @@ int main(int, char const**) {
6566
api_get_transaction_object(&service, req.params["tx"].c_str(),
6667
&json_result);
6768
res.set_header("Content-Type", "application/json");
69+
res.set_header("Access-Control-Allow-Origin", "*");
6870
res << json_result;
6971
});
7072

@@ -86,6 +88,7 @@ int main(int, char const**) {
8688
api_find_transactions_obj_by_tag(&service, req.params["tag"].c_str(),
8789
&json_result);
8890
res.set_header("Content-Type", "application/json");
91+
res.set_header("Access-Control-Allow-Origin", "*");
8992
res << json_result;
9093
});
9194

@@ -104,6 +107,7 @@ int main(int, char const**) {
104107

105108
api_get_tips_pair(&service, &json_result);
106109
res.set_header("Content-Type", "application/json");
110+
res.set_header("Access-Control-Allow-Origin", "*");
107111
res << json_result;
108112
});
109113

@@ -122,6 +126,7 @@ int main(int, char const**) {
122126

123127
api_get_tips(&service, &json_result);
124128
res.set_header("Content-Type", "application/json");
129+
res.set_header("Access-Control-Allow-Origin", "*");
125130
res << json_result;
126131
});
127132

@@ -140,6 +145,7 @@ int main(int, char const**) {
140145

141146
api_generate_address(&service, &json_result);
142147
res.set_header("Content-Type", "application/json");
148+
res.set_header("Access-Control-Allow-Origin", "*");
143149
res << json_result;
144150
});
145151

@@ -170,6 +176,7 @@ int main(int, char const**) {
170176
}
171177

172178
res.set_header("Content-Type", "application/json");
179+
res.set_header("Access-Control-Allow-Origin", "*");
173180
res << json_result;
174181
});
175182

@@ -191,6 +198,7 @@ int main(int, char const**) {
191198

192199
res.set_status(SC_BAD_REQUEST);
193200
res.set_header("Content-Type", "application/json");
201+
res.set_header("Access-Control-Allow-Origin", "*");
194202
res << json;
195203

196204
cJSON_Delete(json_obj);

0 commit comments

Comments
 (0)