Middleware for including CORS to Your express.js application.
npm install --save surprisejs-cors
There are 2 ways:
app.js
const cors = require('surprisejs-cors')
app.use(cors( allowedOrigins, allowedHeaders ))
OR one line option:
app.js
app.use(require('surprisejs-cors)( allowedOrigins, allowedHeaders ))
That's all! :) But...now, You have to understand what means arguments in cors
function and how to set them properly
AllowedOrigins variable can be String[] ( array of strings ) OR just a String. These strings are hostnames of front end applications. For example:
Array of strings:
const allowedOrigins = ['http://localhost:3000', 'https://testapp.firebaseapp.com']
String
const allowedOrigins = 'https://testapp.firebaseapp.com'
Headers is an String containing available HTTP headers which You want to use. For example:
const headers = 'Content-Type, Accept, Authorization'
You can find list of headers here: List of headers
If You get some problems, don't be afraid to contact or create an issue :)
https://github.com/RobertMrowiec/surprisejs-cors
https://www.npmjs.com/package/surprisejs-cors