Last active
December 11, 2015 17:19
-
-
Save botic/4633909 to your computer and use it in GitHub Desktop.
Enable CORS in Stick applications. For details see: https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var config = require("./config/config"); | |
| exports.middleware = function(next, app) { | |
| return function accessControl(request) { | |
| var response; | |
| if (request.method === "OPTIONS") { | |
| // Handle possible preflight requests | |
| response = { | |
| status: 204, // NO CONTENT | |
| headers: { | |
| "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", | |
| "Access-Control-Allow-Headers": "X-Requested-With, Content-Type", | |
| "Access-Control-Max-Age": 120 | |
| }, | |
| body: [""] | |
| }; | |
| } else { | |
| response = next(request); | |
| } | |
| // Globally set the Allow-Origin header for CORS | |
| response.headers["Access-Control-Allow-Origin"] = (config.get("security").enableCORS || "*"); | |
| return response; | |
| }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment