Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated README

Added Contents, OS X Instructions & an example of using a custom logger.
  • Loading branch information...
commit 8573f68bc2059da036db798b8d35dfd6c238c2d2 1 parent 63e0792
@jameswyse jameswyse authored
Showing with 79 additions and 10 deletions.
  1. +79 −10 Readme.md
View
89 Readme.md
@@ -9,6 +9,21 @@ Currently supports `express` version 2.x (not 3.x compatible yet).
Like this module? You should also check out <a href="https://github.com/niftylettuce/node-email-templates" target="_blank">node-email-templates</a>!
+## README Contents
+
+- [Features](#features)
+- [Lazy Web Requests](#requests)
+- [How Does It Work?](#how)
+- [Environment Differences](#environment)
+- [CDN Setup Instructions](#cdn-setup)
+- [Installation](#installation)
+- [Usage](#usage)
+- [Optional Features](#optional)
+ - [Using A Custom Logger](#optional-logger)
+- [Contributors](#contributors)
+- [License](#license)
+
+<a name="features">
## Features
* Built-in optimization of images in production mode using [OptiPNG][1] and [JPEGTran][2].
@@ -23,7 +38,7 @@ Like this module? You should also check out <a href="https://github.com/niftyle
* Uploads changed assets automatically and asynchronously to Amazon S3 (only in production mode) using [knox][10].
-
+<a name="requests">
## Lazy Web Requests
* Automatic parsing of `CDN(...)` in stylesheets and scripts.
@@ -35,7 +50,7 @@ Like this module? You should also check out <a href="https://github.com/niftyle
* Investigate why Chrome Tools Audit returns leverage proxy cookieless jargon.
-
+<a name="how">
## How does it work?
When the server is first started, the module returns a view helper depending on
@@ -45,8 +60,7 @@ searches through your `viewsDir` for any views containing instances of the
it will use your S3 credentials to upload a new copy of the production-quality
assets. Enjoy **:)**.
-
-
+<a name="environment">
## Environment Differences
**Development Mode:**
@@ -58,7 +72,7 @@ Assets are untouched, cachebusted, and delivered as typical local files for rapi
Assets are optimized, minified, mangled, gzipped, delivered by Amazon CloudFront CDN, and hosted from Amazon S3.
-
+<a name="cdn-setup">
## CDN Setup Instructions
1. Visit <https://console.aws.amazon.com/s3/home> and click **Create Bucket**.
@@ -87,19 +101,29 @@ Assets are optimized, minified, mangled, gzipped, delivered by Amazon CloudFront
7. After the DNS change propagates, you can test your new CDN by visiting <http://cdn.your-domain.com> (the `index.html` file should get displayed).
-
+<a name="installation">
## Installation
+### Install Dependencies
+
+##### Linux
```bash
# install optipng and jpegtran packages
sudo apt-get install optipng libjpeg-progs
-
-# install express-cdn module
-npm install express-cdn
```
+##### OS X (with [Homebrew][11])
+```bash
+# install optipng and jpegtran packages
+brew install optipng libjpeg
+```
+### Install express-cdn module
+```bash
+npm install express-cdn
+```
+<a name="usage">
## Usage
### Server
@@ -273,9 +297,52 @@ timestamps together and checks if the combined asset timestamp on S3 exists!).
<!-- #8 - Load and concat two stylesheets -->
<link href="https://cdn.your-site.com/style%2Bextra.1341382571.css" rel="stylesheet" type="text/css" />
```
+<a name="optional">
+## Optional Features
+<a name="optional-logger">
+### Using a custom logger
+By default log messages will be sent to the console. If you would like to use a custom logger function you may pass it in as `options.logger`
+The example below uses the [Winston][12] logging library.
+```javascript
+var winston = require('winston');
+winston.add(winston.transports.File, {filename: 'somefile.log'});
+
+// Set the CDN options
+var options = {
+ publicDir : path.join(__dirname, 'public')
+ , viewsDir : path.join(__dirname, 'views')
+ , domain : 'cdn.your-domain.com'
+ , bucket : 'bucket-name'
+ , key : 'amazon-s3-key'
+ , secret : 'amazon-s3-secret'
+ , hostname : 'localhost'
+ , port : 1337
+ , ssl : false
+ , production : true
+ , logger : winston.info
+};
+
+// Initialize the CDN magic
+var CDN = require('express-cdn')(app, options);
+
+app.configure(function() {
+ app.set('view engine', 'jade');
+ app.set('view options', { layout: false, pretty: true });
+ app.enable('view cache');
+ app.use(express.bodyParser());
+ app.use(express.static(path.join(__dirname, 'public')));
+});
+
+// Add the dynamic view helper
+app.dynamicHelpers({ CDN: CDN });
+
+```
+Any output from express-cdn is now passed to `winston.info()` which writes to both `console` and `somefile.log`.
+
+<a name="contributors">
## Contributors
* Nick Baugh <niftylettuce@gmail.com>
@@ -283,7 +350,7 @@ timestamps together and checks if the combined asset timestamp on S3 exists!).
* Jon Keating <jon@licq.org>
-
+<a name="license">
## License
MIT Licensed
@@ -300,3 +367,5 @@ MIT Licensed
[8]: http://h5bp.com/
[9]: http://nodejs.org/api/zlib.html
[10]: https://github.com/LearnBoost/knox/
+[11]: https://github.com/mxcl/homebrew/
+[12]: https://github.com/flatiron/winston/
Please sign in to comment.
Something went wrong with that request. Please try again.