CORS and adding headers

Practical Serverless Development for Beginners Bonus Lecture - Using your APIs in your front-end app
3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€42.68
List Price:  €59.75
You save:  €17.07
£37.36
List Price:  £52.31
You save:  £14.94
CA$68.96
List Price:  CA$96.55
You save:  CA$27.59
A$75.53
List Price:  A$105.75
You save:  A$30.22
S$64.65
List Price:  S$90.51
You save:  S$25.86
HK$388.99
List Price:  HK$544.63
You save:  HK$155.63
CHF 39.77
List Price:  CHF 55.68
You save:  CHF 15.91
NOK kr506.83
List Price:  NOK kr709.60
You save:  NOK kr202.77
DKK kr318.94
List Price:  DKK kr446.54
You save:  DKK kr127.60
NZ$86.83
List Price:  NZ$121.57
You save:  NZ$34.74
د.إ183.58
List Price:  د.إ257.03
You save:  د.إ73.45
৳6,114.22
List Price:  ৳8,560.40
You save:  ৳2,446.18
₹4,477.97
List Price:  ₹6,269.51
You save:  ₹1,791.54
RM203.80
List Price:  RM285.34
You save:  RM81.54
₦72,958.54
List Price:  ₦102,147.79
You save:  ₦29,189.25
₨14,006.99
List Price:  ₨19,610.91
You save:  ₨5,603.91
฿1,573.74
List Price:  ฿2,203.37
You save:  ฿629.62
₺2,136.85
List Price:  ₺2,991.77
You save:  ₺854.91
B$277.10
List Price:  B$387.96
You save:  B$110.86
R838.78
List Price:  R1,174.36
You save:  R335.58
Лв83.48
List Price:  Лв116.89
You save:  Лв33.40
₩73,773.24
List Price:  ₩103,288.44
You save:  ₩29,515.20
₪160.30
List Price:  ₪224.44
You save:  ₪64.13
₱2,928.48
List Price:  ₱4,100.11
You save:  ₱1,171.62
¥7,886.17
List Price:  ¥11,041.27
You save:  ¥3,155.10
MX$901.50
List Price:  MX$1,262.17
You save:  MX$360.67
QR182.01
List Price:  QR254.83
You save:  QR72.82
P660.38
List Price:  P924.59
You save:  P264.20
KSh6,444.20
List Price:  KSh9,022.40
You save:  KSh2,578.19
E£2,379.02
List Price:  E£3,330.82
You save:  E£951.80
ብር7,766.58
List Price:  ብር10,873.84
You save:  ብር3,107.25
Kz45,840.83
List Price:  Kz64,180.83
You save:  Kz18,340
CLP$45,522.89
List Price:  CLP$63,735.69
You save:  CLP$18,212.80
CN¥351.98
List Price:  CN¥492.80
You save:  CN¥140.82
RD$3,131.60
List Price:  RD$4,384.49
You save:  RD$1,252.89
DA6,499.05
List Price:  DA9,099.19
You save:  DA2,600.14
FJ$114.16
List Price:  FJ$159.83
You save:  FJ$45.67
Q383.08
List Price:  Q536.34
You save:  Q153.26
GY$10,459.45
List Price:  GY$14,644.08
You save:  GY$4,184.62
ISK kr6,280.24
List Price:  ISK kr8,792.84
You save:  ISK kr2,512.60
DH458.25
List Price:  DH641.59
You save:  DH183.33
L846.37
List Price:  L1,184.99
You save:  L338.61
ден2,627.24
List Price:  ден3,678.35
You save:  ден1,051.10
MOP$400.69
List Price:  MOP$561
You save:  MOP$160.31
N$838.67
List Price:  N$1,174.20
You save:  N$335.53
C$1,834.63
List Price:  C$2,568.63
You save:  C$734
रु7,214
List Price:  रु10,100.17
You save:  रु2,886.17
S/168.35
List Price:  S/235.71
You save:  S/67.35
K212.67
List Price:  K297.75
You save:  K85.08
SAR187.49
List Price:  SAR262.50
You save:  SAR75.01
ZK1,131.09
List Price:  ZK1,583.62
You save:  ZK452.52
L216.72
List Price:  L303.43
You save:  L86.70
Kč1,038.78
List Price:  Kč1,454.38
You save:  Kč415.59
Ft16,506.19
List Price:  Ft23,109.99
You save:  Ft6,603.80
SEK kr463.32
List Price:  SEK kr648.68
You save:  SEK kr185.36
ARS$72,528.41
List Price:  ARS$101,545.57
You save:  ARS$29,017.16
Bs345.47
List Price:  Bs483.69
You save:  Bs138.21
COP$192,971.85
List Price:  COP$270,176.04
You save:  COP$77,204.18
₡24,968.35
List Price:  ₡34,957.68
You save:  ₡9,989.33
L1,317.05
List Price:  L1,843.98
You save:  L526.92
₲335,402.41
List Price:  ₲469,590.22
You save:  ₲134,187.80
$U1,959.55
List Price:  $U2,743.53
You save:  $U783.97
zł179.53
List Price:  zł251.36
You save:  zł71.82
Already have an account? Log In

Transcript

Little bit about course, since we are now using all those endpoints. Now, if you try to run your Angular seven app, except localhost like we are using local IP address to run this application, it won't load. Let's investigate it using developer tool. And what's what's happening here. And we see the request access XML HTTP request, which is calling all those endpoints are getting blocked by cause policy, so it says no access control allow origin header is present on the requested resource. So since earlier, we were running the app using local hosts, so it was fine.

Now we are not using local host any more button local IP address to run the app. So let's let's examine lambda function and What What is missing VPC our lambda we haven't defined any cost policy here. So, what you have to do is you have to add a cross origin policy here. So, for the sake of convenience and you can actually use a lot of access control allow origin and course policy in this context what we are going to do is allow all the origins to localhost any IP address or any user can access our endpoint. You can choose to block your access by domain name or IP address. So a specific domain name or specific IP address can only use your endpoints and we can configure that but for the simplicity purpose, we are going to configure and allow all the origins so start.

Now once we have saved this lambda function, we are going to run the app again. And once we run the app again, we see that error has gone. And now we are able to load and use our endpoint successfully. So a little bit and if you are having the same problem, you need to update all your lambda functions with cost policy. Now, a little bit about the cross origin resource setting. So course, is just it's a kind of mechanism where you allow your incoming requests.

So it can be your domain, it can be your s3 bucket, it can be you know, your any, any other front end application. So it just runs on request response model of just just a couple of other jargons pre flight request pre flight response. But those endpoints actually allow on the base of the cost policy and if you haven't got your costs sorted out, you might run into this course issue. So, in the future just remember this. It's a it's a big topic in itself. But let's let's not worry about this at this point of time.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.