CORS npm for Express.js using Connect.js middleware
Connect.js provides middleware for handling requests in Express.js.
You can use node package manager (npm) to install a package that enables CORS in Express.js with Connect.js:
npm install cors
The package offers flexible options, which should be familiar to the CORS
specification, including using credentials and preflight. It provides dynamic ways of validating an origin domain using a function or a regular expression, and handler functions to process preflight.
Configuration options for CORS npm
The following are the options for CORS npm:
origin
: Configures the Access-Control-Allow-Origin
CORS header with a string containing the full URL and protocol making the request, for example http://localdomain.com
.
Possible values for origin
:
The default value
TRUE
usesreq.header('Origin')
to determine the origin and CORS is enabledWhen set to
FALSE
, CORS is disabledIt can be set to a function with the request origin as the first parameter and a callback...