Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 018f534

Browse files
committed
faet: Add CORS header
1 parent e8793b0 commit 018f534

File tree

13 files changed

+192
-28
lines changed

13 files changed

+192
-28
lines changed

backend/api/add_bookmark_blog/lambda_function.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,22 @@ def lambda_handler(event, context):
4141
if user_id is None:
4242
return {
4343
'statusCode': 400,
44+
'headers': {
45+
'Content-Type': 'application/json; charset=utf-8',
46+
'Access-Control-Allow-Origin': '*',
47+
'Access-Control-Allow-Headers': 'Content-Type'
48+
},
4449
'body': json.dumps('Missing user_id')
4550
}
4651

4752
if blog_id is None:
4853
return {
4954
'statusCode': 400,
55+
'headers': {
56+
'Content-Type': 'application/json; charset=utf-8',
57+
'Access-Control-Allow-Origin': '*',
58+
'Access-Control-Allow-Headers': 'Content-Type'
59+
},
5060
'body': json.dumps('Missing blog_id')
5161
}
5262

@@ -58,7 +68,11 @@ def lambda_handler(event, context):
5868
if db_user is None:
5969
return {
6070
'statusCode': 404,
61-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
71+
'headers': {
72+
'Content-Type': 'application/json; charset=utf-8',
73+
'Access-Control-Allow-Origin': '*',
74+
'Access-Control-Allow-Headers': 'Content-Type'
75+
},
6276
'body': json.dumps('User not found')
6377
}
6478

@@ -84,6 +98,10 @@ def lambda_handler(event, context):
8498

8599
return {
86100
'statusCode': 204,
87-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
88-
'body': ""
101+
'headers': {
102+
'Content-Type': 'application/json; charset=utf-8',
103+
'Access-Control-Allow-Origin': '*',
104+
'Access-Control-Allow-Headers': 'Content-Type'
105+
},
106+
'body': ''
89107
}

backend/api/create_user/lambda_function.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def lambda_handler(event, context):
1111
if user_id is None:
1212
return {
1313
'statusCode': 400,
14+
'headers': {
15+
'Content-Type': 'application/json; charset=utf-8',
16+
'Access-Control-Allow-Origin': '*',
17+
'Access-Control-Allow-Headers': 'Content-Type'
18+
},
1419
'body': json.dumps('Missing user_id')
1520
}
1621

@@ -22,7 +27,11 @@ def lambda_handler(event, context):
2227
if db_user:
2328
return {
2429
'statusCode': 405,
25-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
30+
'headers': {
31+
'Content-Type': 'application/json; charset=utf-8',
32+
'Access-Control-Allow-Origin': '*',
33+
'Access-Control-Allow-Headers': 'Content-Type'
34+
},
2635
'body': json.dumps('User already exists')
2736
}
2837

@@ -37,7 +46,11 @@ def lambda_handler(event, context):
3746

3847
return {
3948
'statusCode': 200,
40-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
49+
'headers': {
50+
'Content-Type': 'application/json; charset=utf-8',
51+
'Access-Control-Allow-Origin': '*',
52+
'Access-Control-Allow-Headers': 'Content-Type'
53+
},
4154
'body': json.dumps(
4255
{
4356
"id": db_user.id,

backend/api/delete_bookmark_blog/lambda_function.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@ def lambda_handler(event, context):
1212
if user_id is None:
1313
return {
1414
'statusCode': 400,
15+
'headers': {
16+
'Content-Type': 'application/json; charset=utf-8',
17+
'Access-Control-Allow-Origin': '*',
18+
'Access-Control-Allow-Headers': 'Content-Type'
19+
},
1520
'body': json.dumps('Missing user_id')
1621
}
1722

1823
if blog_id is None:
1924
return {
2025
'statusCode': 400,
26+
'headers': {
27+
'Content-Type': 'application/json; charset=utf-8',
28+
'Access-Control-Allow-Origin': '*',
29+
'Access-Control-Allow-Headers': 'Content-Type'
30+
},
2131
'body': json.dumps('Missing blog_id')
2232
}
2333

@@ -29,7 +39,11 @@ def lambda_handler(event, context):
2939
if db_user is None:
3040
return {
3141
'statusCode': 404,
32-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
42+
'headers': {
43+
'Content-Type': 'application/json; charset=utf-8',
44+
'Access-Control-Allow-Origin': '*',
45+
'Access-Control-Allow-Headers': 'Content-Type'
46+
},
3347
'body': json.dumps('User not found')
3448
}
3549

@@ -39,7 +53,11 @@ def lambda_handler(event, context):
3953
if db_bookmark is None:
4054
return {
4155
'statusCode': 404,
42-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
56+
'headers': {
57+
'Content-Type': 'application/json; charset=utf-8',
58+
'Access-Control-Allow-Origin': '*',
59+
'Access-Control-Allow-Headers': 'Content-Type'
60+
},
4361
'body': json.dumps('Bookmark not found')
4462
}
4563

@@ -48,6 +66,10 @@ def lambda_handler(event, context):
4866

4967
return {
5068
'statusCode': 204,
51-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
69+
'headers': {
70+
'Content-Type': 'application/json; charset=utf-8',
71+
'Access-Control-Allow-Origin': '*',
72+
'Access-Control-Allow-Headers': 'Content-Type'
73+
},
5274
'body': ""
5375
}

backend/api/edit_user_email/lambda_function.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def lambda_handler(event, context):
1111
if user_id is None:
1212
return {
1313
'statusCode': 400,
14+
'headers': {
15+
'Content-Type': 'application/json; charset=utf-8',
16+
'Access-Control-Allow-Origin': '*',
17+
'Access-Control-Allow-Headers': 'Content-Type'
18+
},
1419
'body': json.dumps('Missing user_id')
1520
}
1621

@@ -22,7 +27,11 @@ def lambda_handler(event, context):
2227
if db_user:
2328
return {
2429
'statusCode': 405,
25-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
30+
'headers': {
31+
'Content-Type': 'application/json; charset=utf-8',
32+
'Access-Control-Allow-Origin': '*',
33+
'Access-Control-Allow-Headers': 'Content-Type'
34+
},
2635
'body': json.dumps('User already exists')
2736
}
2837

@@ -32,6 +41,10 @@ def lambda_handler(event, context):
3241

3342
return {
3443
'statusCode': 204,
35-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
44+
'headers': {
45+
'Content-Type': 'application/json; charset=utf-8',
46+
'Access-Control-Allow-Origin': '*',
47+
'Access-Control-Allow-Headers': 'Content-Type'
48+
},
3649
'body': ""
3750
}

backend/api/get_blog/lambda_function.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ def lambda_handler(event, context):
1010
if blog_id is None:
1111
return {
1212
'statusCode': 400,
13+
'headers': {
14+
'Content-Type': 'application/json; charset=utf-8',
15+
'Access-Control-Allow-Origin': '*',
16+
'Access-Control-Allow-Headers': 'Content-Type'
17+
},
1318
'body': json.dumps('Missing blog_id')
1419
}
1520

@@ -21,13 +26,21 @@ def lambda_handler(event, context):
2126
if db_blog is None:
2227
return {
2328
'statusCode': 404,
24-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
29+
'headers': {
30+
'Content-Type': 'application/json; charset=utf-8',
31+
'Access-Control-Allow-Origin': '*',
32+
'Access-Control-Allow-Headers': 'Content-Type'
33+
},
2534
'body': json.dumps('Blog not found')
2635
}
2736

2837
return {
2938
'statusCode': 200,
30-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
39+
'headers': {
40+
'Content-Type': 'application/json; charset=utf-8',
41+
'Access-Control-Allow-Origin': '*',
42+
'Access-Control-Allow-Headers': 'Content-Type'
43+
},
3144
'body': json.dumps(
3245
{
3346
"id": db_blog.id,

backend/api/get_blog_followers/lambda_function.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ def lambda_handler(event, context):
1010
if blog_id is None:
1111
return {
1212
'statusCode': 400,
13+
'headers': {
14+
'Content-Type': 'application/json; charset=utf-8',
15+
'Access-Control-Allow-Origin': '*',
16+
'Access-Control-Allow-Headers': 'Content-Type'
17+
},
1318
'body': json.dumps('Missing blog_id')
1419
}
1520

@@ -21,12 +26,20 @@ def lambda_handler(event, context):
2126
if db_blog is None:
2227
return {
2328
'statusCode': 404,
24-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
29+
'headers': {
30+
'Content-Type': 'application/json; charset=utf-8',
31+
'Access-Control-Allow-Origin': '*',
32+
'Access-Control-Allow-Headers': 'Content-Type'
33+
},
2534
'body': json.dumps('Blog not found')
2635
}
2736

2837
return {
2938
'statusCode': 200,
30-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
39+
'headers': {
40+
'Content-Type': 'application/json; charset=utf-8',
41+
'Access-Control-Allow-Origin': '*',
42+
'Access-Control-Allow-Headers': 'Content-Type'
43+
},
3144
'body': len(db_blog.bookmarks)
3245
}

backend/api/get_bookmark_blog/lambda_function.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ def lambda_handler(event, context):
1111
if user_id is None:
1212
return {
1313
'statusCode': 400,
14+
'headers': {
15+
'Content-Type': 'application/json; charset=utf-8',
16+
'Access-Control-Allow-Origin': '*',
17+
'Access-Control-Allow-Headers': 'Content-Type'
18+
},
1419
'body': json.dumps('Missing user_id')
1520
}
1621

1722
if blog_id is None:
1823
return {
1924
'statusCode': 400,
25+
'headers': {
26+
'Content-Type': 'application/json; charset=utf-8',
27+
'Access-Control-Allow-Origin': '*',
28+
'Access-Control-Allow-Headers': 'Content-Type'
29+
},
2030
'body': json.dumps('Missing blog_id')
2131
}
2232

@@ -28,13 +38,21 @@ def lambda_handler(event, context):
2838
if db_bookmark is None:
2939
return {
3040
'statusCode': 404,
31-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
41+
'headers': {
42+
'Content-Type': 'application/json; charset=utf-8',
43+
'Access-Control-Allow-Origin': '*',
44+
'Access-Control-Allow-Headers': 'Content-Type'
45+
},
3246
'body': json.dumps('Bookmark not found')
3347
}
3448

3549
return {
3650
'statusCode': 200,
37-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
51+
'headers': {
52+
'Content-Type': 'application/json; charset=utf-8',
53+
'Access-Control-Allow-Origin': '*',
54+
'Access-Control-Allow-Headers': 'Content-Type'
55+
},
3856
'body': json.dumps(
3957
{
4058
"id": db_bookmark.id,

backend/api/get_bookmarked_blogs/lambda_function.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ def lambda_handler(event, context):
1010
if user_id is None:
1111
return {
1212
'statusCode': 400,
13+
'headers': {
14+
'Content-Type': 'application/json; charset=utf-8',
15+
'Access-Control-Allow-Origin': '*',
16+
'Access-Control-Allow-Headers': 'Content-Type'
17+
},
1318
'body': json.dumps('Missing user_id')
1419
}
1520

@@ -21,7 +26,11 @@ def lambda_handler(event, context):
2126
if db_user is None:
2227
return {
2328
'statusCode': 404,
24-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
29+
'headers': {
30+
'Content-Type': 'application/json; charset=utf-8',
31+
'Access-Control-Allow-Origin': '*',
32+
'Access-Control-Allow-Headers': 'Content-Type'
33+
},
2534
'body': json.dumps('User not found')
2635
}
2736

@@ -31,7 +40,11 @@ def lambda_handler(event, context):
3140

3241
return {
3342
'statusCode': 200,
34-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
43+
'headers': {
44+
'Content-Type': 'application/json; charset=utf-8',
45+
'Access-Control-Allow-Origin': '*',
46+
'Access-Control-Allow-Headers': 'Content-Type'
47+
},
3548
'body': json.dumps(
3649
[
3750
{

backend/api/get_posts/lambda_function.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ def lambda_handler(event, context):
2323
if db_user is None:
2424
return {
2525
'statusCode': 404,
26-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
26+
'headers': {
27+
'Content-Type': 'application/json; charset=utf-8',
28+
'Access-Control-Allow-Origin': '*',
29+
'Access-Control-Allow-Headers': 'Content-Type'
30+
},
2731
'body': json.dumps('User not found')
2832
}
2933

@@ -35,7 +39,11 @@ def lambda_handler(event, context):
3539

3640
return {
3741
'statusCode': 200,
38-
'headers': {'Content-Type': 'application/json; charset=utf-8', 'Access-Control-Allow-Origin': '*'},
42+
'headers': {
43+
'Content-Type': 'application/json; charset=utf-8',
44+
'Access-Control-Allow-Origin': '*',
45+
'Access-Control-Allow-Headers': 'Content-Type'
46+
},
3947
'body': json.dumps(
4048
[
4149
{

0 commit comments

Comments
 (0)