frock-middleware-cors

1.0.4 • Public • Published

frock-middleware-cors

A simple frock middleware to enable CORS.

Build Status js-standard-style npm

Install

npm install --save-dev frock-middleware-cors

frockfile Example

You would use this middleware in your frockfile.json as follows:

{
  "servers": [
    {
      "port": 8080,
      "routes": [
        {
          "path": "/cors-api",
          "methods": ["GET"],
          "handler": "frock-static",
          "middleware": [
            {
              "handler": "frock-middleware-cors",
              "options": {
                "allowOrigin": "http://foo.com",
                "allowCredentials": true
              }
            }
          ]
        }
      ]
    }
  ]
}

options Configuration

options.allowOrign: String|Array

A string or an array of origins specifies URIs that may access the resource.

It defaults to *.

options: {
  allowOrigin: ['http://foo.com', 'http://bar.com']
}

options.allowMethods: String|Array

A string or an array of methods which are allowed to access the resource.

It defaults to ['GET', 'POST', 'OPTIONS', 'PUT', 'PATCH', 'DELETE', 'CONNECT'].

options: {
  allowMethods: 'GET'
}

options.allowHeaders: String|Array

A string or an array of headers that are used in response to a preflight request to indicate which HTTP headers can be used when the actual request is made.

It defaults to ['X-Requested-With', 'X-HTTP-Method-Override', 'Content-Type', 'Accept'].

options: {
  allowHeaders: 'Content-Type'
}

options.allowCredentials: Boolean|String

Indicates whether or nor the response to the request can be exposed when the crenditials flag is true.

It defaults to false.

options: {
  allowCredentials: true
}

options.maxAge: Integer|String

Indicates how long the results of a preflight request can be cached.

It defaults to 86400.

options: {
  maxAge: '86400'
}

License

WTFPL

Readme

Keywords

Package Sidebar

Install

npm i frock-middleware-cors

Weekly Downloads

32

Version

1.0.4

License

WTFPL

Last publish

Collaborators

  • dorayx