Local asset server for development. Built-in support for cush.
// Create the server.
const cdn = require('cush-cdn')(options);
The server constructor takes these options and returns a slush instance.
Additional options:
bucketDir: ?string
the directory where buckets are cached
Send a GET request to /b/path/to/example.js
with an X-Bucket
header
equal to the desired bucket's unique identifier.
-
Save assets in your project's
./assets/
directory -
Add a
.cushignore
file to the./assets/
directory (optional)- pattern syntax is detailed here
- paths ignored by default are:
/.cushignore
.DS_Store
*.swp
-
Export the
bundles
object in your project'scush.config.js
exports.bundles = {
'main.js': 'bundle.web.js',
'styles/main.css': {
name: 'bundle.css',
target: 'web',
}
};
- Register the project with
cush-cdn
cdn.addProject('/path/to/project');
// Get the default bucket of your project by its name.
cdn.getBucket('my-project');
In the future, you may be able to share buckets between projects.
Register a project with the server.
Its default bucket is created (located at ./assets/
).
Its bundles are registered with the default bucket.
Stop serving a project's assets.
Returns true when a project exists.
Get a Bucket
object by its unique identifier.
Create a Bucket
object.
The given id
string must be unique.
Available options:
root: string
only: ?string[]
whitelist for filenamesskip: ?string[]
blacklist for filenames
Destroy a Bucket
by its unique identifier.
Returns true when a bucket exists.
Properties:
id: string
root: string
dest: string
only: string[]
skip: string[]
events: EventEmitter
The events
property is an se.EventEmitter object.
Returns true if the asset exists.
When an asset is cached on disk, its cached filename is returned. This filename can be used to read the asset from its bucket.
Patch the asset manifest.
See the PATCH /b/assets.json
section for more details.
Add an asset to the bucket.
When the value
is a function, it's passed the HTTP response object
and may return a promise, readable stream, string, or falsy.
Remove an asset from the bucket.
Use wch.query
on the bucket root.
The query API is currently undocumented.
All /b/
requests must include an X-Bucket
header.
Fetch an asset.
The response headers include:
Content-Type
Content-Length
Cache-Control: no-store
Fetch the asset manifest, which maps asset names to their production identifiers.
When a value is true
, the asset name is used as-is in production.
By setting the accepts
header to text/event-stream
, you will receive
change events as they happen. The socket-events protocol is used.
Patch the asset manifest.
The request body must be a JSON object where the keys are asset names
and each value is a string, true
literal, or null
literal.
When a value is null
, the asset is deleted from the bucket.