Giter Club home page Giter Club logo

serverless-polyfill's Introduction

serverless-polyfill

Uses polyfill.io's service to generate a Polyfill based on the user agent of the request. Aggressively caches to ensure as few requests as possible.

Caching

All the responses are cached for a day and varied by the User-Agent header. As the endpoint is the same for all browsers, the Vary by User-Agent header will ensure that cached payloads are different depending upon the browser.

CORS

CORS is enabled by default for all endpoints and allows any origin i.e. *

Getting started

Ensure you have node and either npm or yarn installed globally. Serverless requires Node 8.10.0.


NVM

If you are using a different version of Node, we recommend using nvm to run different versions. Set up the correct Node environment bar running nvm use. This will automatically read the contained .nvmrc file and set the appropriate version.


Run yarn installto fetch all the dependencies and once done, run yarn serve to start a local server at http://localhost:3000.

Deployment

Polyfill allows deployment to AWS Lambda with a single command. Run sls deploy --stage [STAGE] to deploy the function.

Note: If the --stage parameter is not specified, Serverless will default to dev.

Note: The NODE_ENV variable is always forced to be production irrespective of whether the service is running offline or in the cloud. This is so that the Polyfill service will run in production mode.

This will trigger output that looks something like:

Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (57.17 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
..............
Serverless: Stack update finished...
Service Information
service: polyfill
stage: production
region: us-west-2
stack: polyfill-production
api keys:
  None
endpoints:
  GET - https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/production/polyfill
functions:
  polyfill: polyfill-production-polyfill

Usage

Place the endpoint URL in a script tag in your application's HTML before you load your main JavaScript to get all of the necessary polyfills. Polyfill will use your browser's user-agent to determine all the Polyfills that should be loaded.

HTML

View the source of the included debug.html file to see how the Polyfill service should be used on a webpage.

cURL
curl -v http://localhost:3000/polyfill.js

Linting

This service uses Prettier to format and lint it's sources. Run yarn build to prettify all the sources.

Testing

Serverless uses Jest for testing. Run the entire test suite by executing yarn test.

serverless-polyfill's People

Contributors

mridang avatar

Watchers

 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.