connect-assets-cdn

A connect-assets helper for uploading built assets to a CDN (like Amazon S3)

connect-assets-cdn

A helper module for connect-assets to upload your files to a CDN (like Amazon S3)

npm install connect-assets-cdn

assets = require 'connect-assets'
{AssetsCDN} = require 'connect-assets-cdn'

# Snip ...

app.use assets
    servePath: '//s3.amazonaws.com/S3_Bucket'

# You should probably only upload for production
if process.env.NODE_ENV == "production"

    cdn = new AssetsCDN 
        assets: assets
        key: "S3_Key"
        secret: "S3_Secret"
        bucket: "S3_Bucket"

    cdn.upload (err, uploadedPaths) ->
        throw err if err

        app.listen 3000, (err) ->
            console.log "Server started"
  • Check if files exist already on CDN before uploading

Made possible thanks to connect-assets, s3-client, knox.

Created by Jacob Gable. MIT License; no attribution required.