File tree Expand file tree Collapse file tree 16 files changed +168
-24
lines changed Expand file tree Collapse file tree 16 files changed +168
-24
lines changed Original file line number Diff line number Diff line change 1
1
import json
2
2
3
- def output (result ):
3
+ def output (result , headers = {} ):
4
4
status = 200 if result .success () else 400
5
5
payload = result .result if result .success () else convert_to_hashes (result .errors )
6
- return (json .dumps (payload ), status )
6
+ return (json .dumps (payload ), status , headers )
7
7
8
8
def convert_to_hashes (arr ):
9
9
hashes_arr = []
Original file line number Diff line number Diff line change 5
5
6
6
@functions_framework .http
7
7
def dispatcher (request ):
8
+ # For more information about CORS and CORS preflight requests, see:
9
+ # https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
10
+
11
+ # Set CORS headers for the preflight request
12
+ if request .method == "OPTIONS" :
13
+ # Allows GET requests from any origin with the Content-Type
14
+ # header and caches preflight response for an 3600s
15
+ headers = {
16
+ "Access-Control-Allow-Origin" : "*" ,
17
+ "Access-Control-Allow-Methods" : "GET" ,
18
+ "Access-Control-Allow-Headers" : "Content-Type" ,
19
+ "Access-Control-Max-Age" : "3600" ,
20
+ }
21
+
22
+ return ("" , 204 , headers )
23
+
24
+ # Set CORS headers for the main request
25
+ headers = {"Access-Control-Allow-Origin" : "*" }
8
26
args = request .args .to_dict ()
9
27
10
28
validator = Validator (params = args )
@@ -16,4 +34,4 @@ def dispatcher(request):
16
34
17
35
response = list_data (result .result )
18
36
19
- return output (response )
37
+ return output (response , headers )
Original file line number Diff line number Diff line change 1
1
import json
2
2
3
- def output (result ):
3
+ def output (result , headers = {} ):
4
4
status = 200 if result .success () else 400
5
5
payload = result .result if result .success () else convert_to_hashes (result .errors )
6
- return (json .dumps (payload ), status )
6
+ return (json .dumps (payload ), status , headers )
7
7
8
8
def convert_to_hashes (arr ):
9
9
hashes_arr = []
Original file line number Diff line number Diff line change 5
5
6
6
@functions_framework .http
7
7
def dispatcher (request ):
8
+ # For more information about CORS and CORS preflight requests, see:
9
+ # https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
10
+
11
+ # Set CORS headers for the preflight request
12
+ if request .method == "OPTIONS" :
13
+ # Allows GET requests from any origin with the Content-Type
14
+ # header and caches preflight response for an 3600s
15
+ headers = {
16
+ "Access-Control-Allow-Origin" : "*" ,
17
+ "Access-Control-Allow-Methods" : "GET" ,
18
+ "Access-Control-Allow-Headers" : "Content-Type" ,
19
+ "Access-Control-Max-Age" : "3600" ,
20
+ }
21
+
22
+ return ("" , 204 , headers )
23
+
24
+ # Set CORS headers for the main request
25
+ headers = {"Access-Control-Allow-Origin" : "*" }
8
26
args = request .args .to_dict ()
9
27
10
28
validator = Validator (params = args )
@@ -16,4 +34,4 @@ def dispatcher(request):
16
34
17
35
response = list_data (result .result )
18
36
19
- return output (response )
37
+ return output (response , headers )
Original file line number Diff line number Diff line change 1
1
import json
2
2
3
- def output (result ):
3
+ def output (result , headers = {} ):
4
4
status = 200 if result .success () else 400
5
5
payload = result .result if result .success () else convert_to_hashes (result .errors )
6
- return (json .dumps (payload ), status )
6
+ return (json .dumps (payload ), status , headers )
7
7
8
8
def convert_to_hashes (arr ):
9
9
hashes_arr = []
Original file line number Diff line number Diff line change 5
5
6
6
@functions_framework .http
7
7
def dispatcher (request ):
8
+ # For more information about CORS and CORS preflight requests, see:
9
+ # https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
10
+
11
+ # Set CORS headers for the preflight request
12
+ if request .method == "OPTIONS" :
13
+ # Allows GET requests from any origin with the Content-Type
14
+ # header and caches preflight response for an 3600s
15
+ headers = {
16
+ "Access-Control-Allow-Origin" : "*" ,
17
+ "Access-Control-Allow-Methods" : "GET" ,
18
+ "Access-Control-Allow-Headers" : "Content-Type" ,
19
+ "Access-Control-Max-Age" : "3600" ,
20
+ }
21
+
22
+ return ("" , 204 , headers )
23
+
24
+ # Set CORS headers for the main request
25
+ headers = {"Access-Control-Allow-Origin" : "*" }
8
26
args = request .args .to_dict ()
9
27
10
28
validator = Validator (params = args )
@@ -16,4 +34,4 @@ def dispatcher(request):
16
34
17
35
response = list_data (result .result )
18
36
19
- return output (response )
37
+ return output (response , headers )
Original file line number Diff line number Diff line change 1
1
import json
2
2
3
- def output (result ):
3
+ def output (result , headers = {} ):
4
4
status = 200 if result .success () else 400
5
5
payload = result .result if result .success () else convert_to_hashes (result .errors )
6
- return (json .dumps (payload ), status )
6
+ return (json .dumps (payload ), status , headers )
7
7
8
8
def convert_to_hashes (arr ):
9
9
hashes_arr = []
Original file line number Diff line number Diff line change 6
6
7
7
@functions_framework .http
8
8
def dispatcher (request ):
9
+ # For more information about CORS and CORS preflight requests, see:
10
+ # https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
11
+
12
+ # Set CORS headers for the preflight request
13
+ if request .method == "OPTIONS" :
14
+ # Allows GET requests from any origin with the Content-Type
15
+ # header and caches preflight response for an 3600s
16
+ headers = {
17
+ "Access-Control-Allow-Origin" : "*" ,
18
+ "Access-Control-Allow-Methods" : "GET" ,
19
+ "Access-Control-Allow-Headers" : "Content-Type" ,
20
+ "Access-Control-Max-Age" : "3600" ,
21
+ }
22
+
23
+ return ("" , 204 , headers )
24
+
25
+ # Set CORS headers for the main request
26
+ headers = {"Access-Control-Allow-Origin" : "*" }
9
27
10
28
response = Result (result = COUNTRIES )
11
29
12
- return output (response )
30
+ return output (response , headers )
Original file line number Diff line number Diff line change 1
1
import json
2
2
3
- def output (result ):
3
+ def output (result , headers = {} ):
4
4
status = 200 if result .success () else 400
5
5
payload = result .result if result .success () else convert_to_hashes (result .errors )
6
- return (json .dumps (payload ), status )
6
+ return (json .dumps (payload ), status , headers )
7
7
8
8
def convert_to_hashes (arr ):
9
9
hashes_arr = []
Original file line number Diff line number Diff line change 5
5
6
6
@functions_framework .http
7
7
def dispatcher (request ):
8
+ # For more information about CORS and CORS preflight requests, see:
9
+ # https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
10
+
11
+ # Set CORS headers for the preflight request
12
+ if request .method == "OPTIONS" :
13
+ # Allows GET requests from any origin with the Content-Type
14
+ # header and caches preflight response for an 3600s
15
+ headers = {
16
+ "Access-Control-Allow-Origin" : "*" ,
17
+ "Access-Control-Allow-Methods" : "GET" ,
18
+ "Access-Control-Allow-Headers" : "Content-Type" ,
19
+ "Access-Control-Max-Age" : "3600" ,
20
+ }
21
+
22
+ return ("" , 204 , headers )
23
+
24
+ # Set CORS headers for the main request
25
+ headers = {"Access-Control-Allow-Origin" : "*" }
8
26
args = request .args .to_dict ()
9
27
10
28
validator = Validator (params = args )
@@ -16,4 +34,4 @@ def dispatcher(request):
16
34
17
35
response = list_data (result .result )
18
36
19
- return output (response )
37
+ return output (response , headers )
You can’t perform that action at this time.
0 commit comments