npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-aws-static-file-handler

v4.1.0

Published

Easily serve static files with the Serverless Framework on AWS Lambda.

Downloads

4,232

Readme

npm version npm Build Status Coverage Status License GitHub stars

serverless-aws-static-file-handler

Host the front-end of your web applications on Serverless framework on AWS Lambda right alongside the API.

It is a fast and easy way to get started and makes it trivial to deploy your web applications. If you need better response time in the future and get concerned about AWS costs of using Lambda to static content, you put CloudFront in front of your Serverless endpoints service static content.

Usage / Quick Start

Import & initialize:

const StaticFileHandler = require('serverless-aws-static-file-handler')

# configure where to serve files from:
const clientFilesPath = path.join(__dirname, "./data-files/")
const fileHandler = new StaticFileHandler(clientFilesPath)

Define a handler in your code as follows:

module.exports.html = async (event, context) => {
  event.path = "index.html" // forcing a specific page for this handler, ignore requested path. This would serve ./data-files/index.html
  return fileHandler.get(event, context)
}

In your serverless.yml file, reference the handler function from above to provide routes to your static files:

functions:
  html:
    handler: handler.html
    events:
      - http:
          path: /
          method: get

  # Note Binary files work too! See configuration information below
  png:
    handler: handler.png
    events:
      - http:
          path: png
          method: get

  # The following example uses a path placeholder to serve all files directly in the /binary/ directory:
  binary:
    handler: handler.binary
    events:
      - http:
        path: /binary/{pathvar+}
        method: get

To serve binary content make sure that you setup the plugin in your serverless.yml like so:

plugins:
  - serverless-aws-static-file-handler/plugins/BinaryMediaTypes

custom:
  apiGateway:
    binaryMediaTypes:
      - "image/png"
      - "image/jpeg"

Some additional real-world examples are demonstrated in the examples/basic/ directory as well as a serverless-offline-specific example in examples/serverless-offline/.

Prerequisites / Usage Requirements

Requires Node.js latest, LTS, or v10 (tested).

Requires Serverless Framework v1.x. If you are new to the Serverless Framework, check out the Serverless Framework Getting Started Guide.

Install

Install with yarn (yarn add serverless-aws-static-file-handler) or npm (npm install serverless-aws-static-file-handler --save-prod)

Features

  • Simple to get started
  • Works with text files such as HTML or binary files such as images or fonts

Contributing 🤝

This is a community project. We invite your participation through issues and pull requests! You can peruse the contributing guidelines.

Show your support

Give a ⭐️ if this project helped you!

Release Process (Deploying to NPM)

We use semantic-release to consistently release semver-compatible versions. This project deploys to multiple npm distribution tags. Each of the below branches correspond to the following npm distribution tags:

| branch | npm distribution tag | | ------ | -------------------- | | main | latest | | beta | beta |

To trigger a release use a Conventional Commit following Angular Commit Message Conventions on one of the above branches.

License 📝

Copyright © 2017 [email protected].

This project is MIT licensed.