CORS Express 4.x
const express = require('express');
const CORS = require( './modules/cross-origin.js' );
const app = express();
app.use( CORS );| /** | |
| * Adds CORS ( Cross-origin resource sharing ) headers to the response | |
| * | |
| * @param {object} request the Request object | |
| * @param {object} response the Response object | |
| * @param {function} next function to continue execution | |
| * | |
| * @return {void} | |
| */ | |
| module.exports = ( request, response, next ) => { | |
| response.set({ | |
| 'Access-Control-Allow-Origin': '*', | |
| 'Access-Control-Allow-Methods': 'DELETE,HEAD,GET,PATCH,POST,PUT', | |
| 'Access-Control-Allow-Headers': 'Content-Type, Authorization' | |
| }); | |
| if(request.method === 'OPTIONS') { | |
| response.send(200); | |
| } else { | |
| next(); | |
| } | |
| }; |