Giter Club home page Giter Club logo

docker-s3-spa-loader's Introduction

wonderlic/s3-spa-loader

Links

Description

This docker image will start a node.js webserver and serve up the primary single page app html file associated with a request's incoming hostname. The served SPA file is retrieved from an AWS S3 Bucket (and cached in local memory) where the filename matches the incoming hostname (without any file extension).

HTTP -> HTTPS Redirection: Incoming insecure requests can automatically be redirected to their secure version (OPTIONAL)

The /sns/cache-clear route can be subscribed to an AWS SNS Topic where published AWS S3 Events will clear the associated file from the local memory cache when there are changes made to the file in the AWS S3 Bucket.

The /heartbeat route can be used as a health check with a load balancer (i.e. AWS ALB) to verify the service is still up and running.

Usage

docker run \
  -e PORT=... \
  -e TRUST_PROXY=... \
  -e REDIRECT_INSECURE=... \
  -e AWS_S3_BUCKET_NAME=... \
  wonderlic/s3-spa-loader

If not set:

  • PORT defaults to 8080
  • TRUST_PROXY defaults to true
  • REDIRECT_INSECURE defaults to true

AWS S3 Permissions

The AWS S3 Bucket needs to allow the ListBucket and GetObject permissions.

Example Bucket Policy:

{
    "Version": "2008-10-17",
    "Id": "PolicyForS3SpaLoader",
    "Statement": [
        {
            "Sid": "1",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::BUCKET_NAME"
        },
        {
            "Sid": "2",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::BUCKET_NAME/*"
        }
    ]
}

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.