
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
s3-spa-uploader
Advanced tools
Upload a single page application to S3 with the right content-type and cache-control meta-data
Fork of s3-spa-upload
Upload a Single Page Application (React, Angular, Vue, ...) to S3 with the right content-type and cache-control meta-data
This requires the following AWS S3 permissions (see sample CloudFormation policy template below):
To install globally:
npm install -g s3-spa-uploader
To install locally
npm install --save-dev s3-spa-uploader
Basic usage:
s3-spa-uploader dist-dir my-s3-bucket-name
To also clean up old files, use the --delete option. This will delete all files in the bucket that are not included in the current upload (limited to the supplied prefix, see below):
s3-spa-uploader dist-dir my-s3-bucket-name --delete
You can provide your desired cache-control mapping in a json file that contains a mapping from glob patterns to cache-control headers:
{
"index.html": "no-cache",
"*.js": "public,max-age=31536000,immutable"
}
Suppose your mapping file is called cache-control.json
:
s3-spa-uploader dist-dir my-s3-bucket-name --cache-control-mapping cache-control.json
If you don't provide a custom mapping, the default will be used, which should be okay for most SPA's, see below.
By default the SPA will be uploaded to the root of your S3 bucket. If you don't want this, specify the prefix to use:
s3-spa-uploader dist-dir my-s3-bucket-name --prefix mobile
Note that when used in conjunction with --delete
, this means only old files matching that same prefix will be deleted.
import s3SpaUploader from 's3-spa-uploader';
// const s3SpaUploader = require('s3-spa-uploader')
s3SpaUploader('dir', 'bucket').catch(console.error);
// Can supply options:
const options = {
delete: true,
verbose: true,
prefix: 'mobile',
cacheControlMapping: {
'index.html': 'no-cache',
'*.js': 'public,max-age=31536000,immutable',
},
awsCredentials: {
accessKeyId: '...'
secretAccessKey: '...'
sessionToken: '...'
},
mimeTypeMapping: {
".html": "text/html",
".json": "application/json"
}
}
s3SpaUploader('dir', 'bucket', options).catch(console.error);
File/ext | Cache setting | Description |
---|---|---|
index.html | no-cache | |
css | public,max-age=31536000,immutable | As long as possible |
js | public,max-age=31536000,immutable | As long as possible |
png | public,max-age=86400 | One day |
ico | public,max-age=86400 | One day |
txt | public,max-age=86400 | One day |
Based on file extensions using https://www.npmjs.com/package/mime-types
You can also provide custom mime types (these have higher prioerty than the mime-types extension)
{
".html": "text/html",
".json": "application/json"
}
This CloudFormation IAM Policy template grants the needed permissions:
- Version: "2012-10-17"
Statement:
- Effect: Allow # This effect is only needed when using the --delete option
Action: s3:ListBucket
Resource: arn:aws:s3:::your-bucket-name
- Effect: Allow
Action:
- s3:DeleteObject # This action is only needed when using the --delete option
- s3:PutObject
Resource: arn:aws:s3:::your-bucket-name/*
FAQs
Upload a single page application to S3 with the right content-type and cache-control meta-data
The npm package s3-spa-uploader receives a total of 4 weekly downloads. As such, s3-spa-uploader popularity was classified as not popular.
We found that s3-spa-uploader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.