cush-cdn v0.0.3
cush-cdn v0.0.3
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: ?stringthe directory where buckets are cached
Fetching an asset
Send a GET request to /b/path/to/example.js with an X-Bucket header
equal to the desired bucket's unique identifier.
Adding a project
Save assets in your project's
./assets/directoryAdd a
.cushignorefile to the./assets/directory (optional)- pattern syntax is detailed here
- paths ignored by default are:
/.cushignore.DS_Store*.swp
Export the
bundlesobject 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.
JavaScript API
loadProject(root: string): void
Register a project with the server.
Its default bucket is created (located at ./assets/).
Its bundles are registered with the default bucket.
dropProject(root: string): boolean
Stop serving a project's assets.
Returns true when a project exists.
getBucket(id: string): ?Bucket
Get a Bucket object by its unique identifier.
loadBucket(id: string, options: ?Object)
Create a Bucket object.
The given id string must be unique.
Available options:
root: stringonly: ?string[]whitelist for filenamesskip: ?string[]blacklist for filenames
dropBucket(id: string): boolean
Destroy a Bucket by its unique identifier.
Returns true when a bucket exists.
Bucket class
Properties:
id: stringroot: stringdest: stringonly: string[]skip: string[]events: EventEmitter
The events property is an se.EventEmitter object.
has(name: string): boolean
Returns true if the asset exists.
get(name: string): ?string|function
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(values: Object): void
Patch the asset manifest.
See the PATCH /b/assets.json section for more details.
put(name: string, value: string|function): void
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.
delete(name: string): void
Remove an asset from the bucket.
query(options: Object): Promise<Object>
Use wch.query on the bucket root.
The query API is currently undocumented.
REST API
All /b/ requests must include an X-Bucket header.
GET /b/[asset]
Fetch an asset.
The response headers include:
Content-TypeContent-LengthCache-Control: no-store
GET /b/assets.json
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 /b/assets.json
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.