From 49cbfaf887907677a1ffd866bcd4787ad03906f7 Mon Sep 17 00:00:00 2001 From: Abhishek Biswal Date: Fri, 23 Feb 2018 12:19:45 +0530 Subject: [PATCH] docs: add note for rest tools / servers in dynamic origin example closes #142 --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 3c6bfdd..c238cb8 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,21 @@ app.listen(80, function () { }) ``` +If you do not want to block REST tools or server-to-server requests, +add a `!origin` check in the origin function like so: + +```javascript +var corsOptions = { + origin: function (origin, callback) { + if (whitelist.indexOf(origin) !== -1 || !origin) { + callback(null, true) + } else { + callback(new Error('Not allowed by CORS')) + } + } +} +``` + ### Enabling CORS Pre-Flight Certain CORS requests are considered 'complex' and require an initial