Socket
Socket
Sign inDemoInstall

serverless-cors-plugin

Package Overview
Dependencies
7
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    serverless-cors-plugin

Serverless CORS Plugin - Managing Cross-origin resource sharing (CORS) policies


Version published
Weekly downloads
264
decreased by-11.41%
Maintainers
1
Install size
6.24 MB
Created
Weekly downloads
 

Readme

Source

Serverless CORS Plugin

A Serverless Plugin for the Serverless Framework which adds support for CORS (Cross-origin resource sharing).

serverless npm version Build Status Dependencies Status DevDependencies Status

THIS PLUGIN REQUIRES SERVERLESS V0.5 OR HIGHER!

Introduction

This plugins does the following:

  • It will add CORS response headers to all resource methods with a CORS-policy configured.

  • It will add an OPTIONS preflight endpoint with the proper headers for all resources with a CORS-policy configured.

Installation

In your project root, run:

npm install --save serverless-cors-plugin

Add the plugin to s-project.json:

"plugins": [
  "serverless-cors-plugin"
]

To find the best compatible (major) version, use the table below:

Serverless versionPlugin version
v0.1v0.1
v0.2-v0.3v0.2
v0.4v0.3
v0.5v0.4

Usage

Add the following properties to s-function.json to configure a CORS-policy:

"custom": {
  "cors": {
    "allowOrigin": "*",
    "allowHeaders": ["Content-Type", "X-Amz-Date", "Authorization", "X-Api-Key"]
  }
}

The allowOrigin property is required, the other headers are optional. You can also add this configuration to s-project.json instead of s-function.json to apply the CORS-policy project-wide.

Run endpoint deploy and the CORS headers will dynamically be configured and deployed. Use the -a / --all flag to deploy pre-flight OPTIONS endpoints.

Caution: you will probably notice some warnings on missing stage and region template variables. These can be ignored until the issue is fixed.

Options

These are all options you can use:

OptionTypeExample
allowOriginString"*"
allowHeadersArray["Content-Type", "X-Api-Key"]
allowCredentialsBooleantrue
exposeHeadersArray["Content-Type", "X-Api-Key"]
maxAgeNumber3600

For more information, read the CORS documentation.

Roadmap

  • Dynamically set origin headers (#2)
  • Add more verbose (debugging) output
  • Better support for authenticated requests

License

ISC License. See the LICENSE file.

Keywords

FAQs

Last updated on 08 Sep 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc