Task
To enable CORS on a Kitura server hosted on Bluemix.
Development machine
OS X 10.12.1, Swift version 3.0.2.
Deployed to
Ubuntu 14.04, Swift 3.0.1.
Code
I am using Kitura-CORS
middleware from IBM to enable CORS.
.Package(url: "https://github.com/IBM-Swift/Kitura-CORS", majorVersion: 1, minor: 4)
Here's how I've configured the app:
let options = Options(allowedOrigin: .all, credentials: true, exposedHeaders: ["X-Access-Token"])
let cors = CORS(options: options)
self.router.all(middleware: cors)
Findings
A
OPTIONS
request tohttps://adeptness.eu-gb.mybluemix.net
from Postman returns the following headers:- Connection → Keep-Alive
- Content-Type → text/html
- Date → Wed, 21 Dec 2016 19:12:04 GMT
- Transfer-Encoding → chunked
- X-Backside-Transport → OK OK
- X-Global-Transaction-ID → 4203875359
The app passes the test at Test CORS for a
GET
request tohttps://adeptness.eu-gb.mybluemix.net
and reports the following exposed response headers:- Content-Type → text/html
Issue
I'm not entirely sure if CORS is setup properly. Why is there no X-Access-Token
header in the OPTIONS
response in Finding #1?
I've read Mozilla's documentation on CORS, and although I do understand that browsers pre-flight requests and block all CORS request unless explicitly allowed by the server. What I couldn't find was any resource on how to go about testing CORS server-side without having to mock up a "test" front-end.
How should one go about testing CORS?