Allows access of resources from remote hosts. It allows resources that live in one URL to be loaded into another URL. It is part of the Browser Origin Policy.
Installation
npm install cors
Cross Origin Request Process
Request sent from a origin, and is received by a different origin
- Server adds an access control origin header to the top of the response
It must match the origin in the request, or it can be a wildcard
*
to allow sharing with any origin
If the origins in the response and the request are mismatched, then the browser will respond with a CORS error
Allowing CORS in ExpressJS
Enable the CORS Middleware
...
import cors from 'cors'
app.use(cors({ origin : "http://somerequestedweb.com"}))
...