Code Monkey home page Code Monkey logo

kitura-cors's Introduction

Kitura-CORS

Kitura CORS middleware

Build Status - Master Mac OS X Linux Apache 2

Summary

Kitura CORS middleware.

Swift version

The latest version of Kitura-CORS requires Swift 4.0. You can download this version of the Swift binaries by following this link. Compatibility with other Swift versions is not guaranteed.

API

To create an instance of Kitura-CORS middleware use:

public init(options : Options)

where possible Options are:

  • allowedOrigin - an enum that configures the Access-Control-Allow-Origin CORS server response header. Possible values:
    • all - all origins are allowed. Access-Control-Allow-Origin will be set to *. This is the default.
    • set - a set of allowed origins.
    • origin - single allowed origin.
    • regex - a regular expression that defines allowed origins.
  • credentials - a boolean value that configures the Access-Control-Allow-Credentials CORS header. Is set only if equals to true, otherwise the header is not passed. Defaults to false.
  • methods - an array of methods to be passed in Access-Control-Allow-Methods header. The default is ["GET","HEAD","PUT","PATCH","POST","DELETE"].
  • allowedHeaders - an array of allowed headers to configure the Access-Control-Allow-Headers CORS header. If not specified, the headers specified in the request's Access-Control-Request-Headers header are passed.
  • maxAge - an integer to set the Access-Control-Allow-Max-Age header. If not set, the header is omitted.
  • exposedHeaders - an array of exposed headers to configure the Access-Control-Expose-Headers header. If not set, the header is omitted.
  • preflightContinue - a boolean that defines whether to pass the CORS preflight response to the next handler. Defaults to false.

Please see CORS documentation for details.

Example

First create an instance of CORS:

import KituraCORS

let options = Options(allowedOrigin: .origin("www.abc.com"), methods: ["GET","PUT"], allowedHeaders: ["Content-Type"], maxAge: 5)
let cors = CORS(options: options)

Kitura-CORS is RouterMiddleware. To connect it to the desired path use one of the Router methods:

router.all("/cors", middleware: cors)

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.

kitura-cors's People

Contributors

shmuelk avatar irar2 avatar bdhernand avatar ianpartridge avatar vadimeisenbergibm avatar na-gupta avatar sdrpa avatar dfirsht avatar quanvo87 avatar rolivieri avatar youming-lin avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.