Coder Social home page Coder Social logo

asap's Introduction

@architect/asap

Architect Static Asset Proxy (ASAP) - a helpful library for Lambda-based static asset delivery

GitHub CI status

Usage

Module

Call ASAP within your handler function manually like so:

let asap = require('@architect/asap')

// All config is optional!
module.exports = asap({
  // Alias assets to different filenames
  alias: {
    '/an-asset.jpg': '/a-different-filename.jpg',
    '/a-path': '/a-different-path',
  },
  // Pass your own fingerprinted static asset manifest (defaults to Arc-generated static.json)
  assets: { 'some-file.gif': 'some-file-a1b2c3.gif' },
  // Set a custom bucket configuration (defaults to Arc-generated buckets)
  bucket: {
    staging: 'staging-bucket-name',
    production: 'production-bucket-name',
    folder: 'some-bucket-subfolder',
  },
  // Override the content-aware cache-control header
  cacheControl: 'max-age=0',
  // Manually set response headers
  headers: { 'some-header': 'ok=true' },
  // Return null if asset is not found (defaults to `false`)
  passthru: true,
  // Engage SPA mode (defaults to `false`)
  spa: false,
})

Lambda handler

Use ASAP as the handler for your Lambda! If you're using Architect, this is done automatically for you when you don't define a root handler for your @http pragma.

If using ASAP with non-Architect projects, just point your Lambda's source directory to src/, and make sure you set the following two env vars:

  • ARC_ENV: staging or production
  • ARC_STATIC_BUCKET: the S3 bucket name where your assets are stored

asap's People

Contributors

brianleroux avatar dependabot-preview[bot] avatar ryanblock avatar shawnhosea avatar tbeseda avatar

Watchers

 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.