CORS in 100 Seconds
Key Takeaways
This video teaches the basics of Cross-Origin Resource Sharing or CORS
Full Transcript
cross-origin resource sharing or cores is a mechanism that allows a website on one url to request data from a different url and it's frustrated both front-end and back-end developers since the dawn of time you may have tried to use an image on your website that lives on a different url only to end up with a broken image or your website might try to fetch data from your api then fail with a coors error in the console that happens because the browser implements the same origin policy as part of its security model which allows a website to freely request images and data from its own url but blocks anything from an external url unless certain conditions are met when the browser makes a request it adds an origin header to the request message if that request goes to a server on the same origin then it's allowed by the browser with no questions asked however if that request goes to a different url then it's known as a cross origin request when sending the response the server will add the access control allow origin header its value needs to match the origin header on the request or it can be a wild card which allows any url to make the request if it's a mismatch though the browser will prevent the response data from being shared with the client this results in an error in the browser but for security reasons there's very limited information about what actually went wrong the solution to a corsair lies on the server if you don't control the server you're out of luck if you do control it you likely just need to configure it to respond with a proper header in express.js for example that can be achieved with a single line of middleware code which tells the server to include the course headers on every response now certain http requests like put or any request with a non-standard header will need to be preflighted and just like at the airport it's a sanity check that ensures the passenger or request is safe to fly on the airplane or server the browser automatically knows when to preflight and will first make a request using the options http verb the server will then respond saying yes i allow this origin to make requests with the following methods at which point the main request can happen without fear of disaster that may sound inefficient but the server can respond with a max age header allowing the browser to cache a preflight for a certain amount of time if you happen to be facing a coors error right now open the network tab in the browser find the response and look for the access control allow origin header if it doesn't exist you need to enable cores on your server if it does exist the url may be a mismatch with the website or if it was preflighted it may not be allowing those methods or headers in the request all of which are things you can configure on the server this has been cross origin resource sharing in 100 seconds thanks for watching and i will see you in the next one
Original Description
Cross-Origin Resource Sharing or CORS is a mechanism that allows browsers to request data from 3rd party URLs (or origins) and is a common pain point for web developers. Learn the basics of CORS in 100 seconds.
Full Tutorials
Use CORS in Firebase Cloud Functions https://fireship.io/lessons/secure-firebase-cloud-functions/
Helpful CORS Resources
https://web.dev/cross-origin-resource-sharing/
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
#webdev #js #100SecondsOfCode
Install the quiz app 🤓
iOS https://itunes.apple.com/us/app/fireship/id1462592372?mt=8
Android https://play.google.com/store/apps/details?id=io.fireship.quizapp
Upgrade to Fireship PRO at https://fireship.io/pro
Use code lORhwXd2 for 25% off your first payment.
My VS Code Theme
- Atom One Dark
- vscode-icons
- Fira Code Font
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Fireship · Fireship · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Angular 4 Development and Production Environments with Firebase
Fireship
OAuth with Angular and Firebase Tutorial
Fireship
Anonymous Authentication with Angular and Firebase - Lazy Registration
Fireship
Angular Router Guards for Firebase Users
Fireship
Angular Firebase CRUD App with NoSQL Database Tutorial
Fireship
Upload Files from Angular to Firebase Storage
Fireship
How to Deploy an Angular App to Firebase Hosting
Fireship
Sharing Data between Components in Angular
Fireship
Loading Spinners for Asynchronous Firebase Data
Fireship
Angular 4 Transactional Email with Google Firebase Cloud Functions
Fireship
Firebase Database Rules Tutorial
Fireship
Autocomplete Search with Angular4 and Firebase
Fireship
Reddit Inspired Upvoting System with Angular and Firebase NoSQL
Fireship
Angular Drag-and-Drop File Uploads to Firebase Storage
Fireship
Text Translation with Firebase Cloud Functions onWrite and Angular 4
Fireship
Custom Usernames with Firebase Authentication
Fireship
Twitter-Inspired Follow Unfollow Feature with Firebase and Angular 4
Fireship
Simple Pagination with Firebase and Angular 4
Fireship
How to Connect Firebase Users to their Data - 3 Methods
Fireship
Add Toast Message Notifications to your Angular App
Fireship
Facebook-Inspired Reactions System with Angular and Firebase
Fireship
Learn NgModule in Angular with Examples
Fireship
Lazy Loading Components in Angular 4
Fireship
Stripe Checkout Payments with Angular and Firebase - Part 1
Fireship
Process Stripe Payments with Firebase Cloud Functions - Part 2
Fireship
Selling Digital Content in Angular with Stripe Payments - Part 3
Fireship
Angular 4 Full Text Search with Algolia - Part 1
Fireship
Algolia with Firebase Cloud Functions - Part 2
Fireship
Firebase Phone Authentication in Angular 4
Fireship
Top 7 RxJS Concepts for Angular Developers
Fireship
Learn Angular Animations with 5 Examples
Fireship
Advanced Firebase Data Filtering (Multi-Property)
Fireship
Realtime Maps with Mapbox + Firebase + Angular
Fireship
Angular Reactive Forms with Firebase Database Backend
Fireship
Send Push Notifications in Angular with Firebase Cloud Messaging
Fireship
Top 7 Ways to Debug Angular 4 Apps
Fireship
Infinite Scroll with Angular and Firebase
Fireship
Use TypeScript with Firebase Cloud Functions
Fireship
Realtime Graphs and Charts with Plotly and Firebase
Fireship
Role-Based User Permissions in Firebase
Fireship
User Presence System in Realtime - Online, Offline, Away
Fireship
Location-based Queries with GeoFire and Angular Google Maps
Fireship
Angular ngrx Redux Quick Start Tutorial
Fireship
Angular Ngrx Effects with Firebase Database
Fireship
Progressive Web Apps with Angular
Fireship
Angular Ngrx with Firebase Google OAuth User Authentication
Fireship
RxJS Quick Start with Practical Examples
Fireship
Send SMS Text Messages with Twilio and Firebase
Fireship
Firebase Database Performance Profiling
Fireship
Native Desktop Apps with Angular and Electron
Fireship
Subscription Payments with Stripe, Angular, and Firebase
Fireship
Firestore with AngularFire5 Quick Start Tutorial
Fireship
Angular HTTP Client Quick Start Tutorial
Fireship
Google Sign-In with Firestore Custom User Data
Fireship
Star Review System from Scratch with Firestore + Angular
Fireship
Angular Chatbot with Dialogflow (API.ai)
Fireship
Learn @ngrx/entity and Feature Modules
Fireship
Infinite Scroll Pagination with Firestore
Fireship
Faster Firestore via Data Aggregation
Fireship
Contentful - CMS for Angular Progressive Web Apps
Fireship
Related Reads
📰
📰
📰
📰
Three Token-2022 Mints in One Week: Fees, Yield, and Soulbound
Dev.to · atharv shukla
Maximize Google Workspace AI Power: Safeguard Data and Boost Performance in 2026
Dev.to AI
What is Gemini Spark, and what can it actually do for you?
TechCabal
How I use python to save hours every week
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI