File: README.md

package info (click to toggle)
mirror.js 0.3.3-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 104 kB
  • ctags: 35
  • sloc: makefile: 5
file content (54 lines) | stat: -rw-r--r-- 1,829 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Mirror

Aggregates JavaScript, CSS and any other text files for serving them to browsers with [express](http://expressjs.com/). Supports wrapping and postprocessing outputs. A *mirror* can contain files, plain source code or other mirrors.

### Usage

```javascript
var mirror = require('mirror');

// Mirror guesses the MIME type based on the first file's extension.
var styles = new mirror([
    __dirname + '/assets/main.css',
    __dirname + '/assets/layout.css'
]);

// Proving direct source input requires specifying the MIME type manually.
var configuration = new mirror([
    // Mirror automatically inserts line breaks and semicolons before/after
    // each item in a "js" type mirror.
    mirror('var basepath = "/"'),
    mirror('var config = ' + JSON.stringify(config)),

    // You can add functions to the mirror. They will be called on each request.
    mirror(function(callback, req, res) {
        callback(null, 'var url = ' + JSON.stringify(req.url));
    })
], {
    type: 'js',
    maxAge: 60  // Only cache configuration file for 60 seconds.
});

// Store the array of files and remove or add files on-the-fly.
var files = [
    require.resolve('underscore'),
    require.resolve('backbone'),
    require.resolve('mymodule/client.js'),

    // Add other mirrors
    configuration
];

// Add the mirrors to your express server.
app.get('/assets/style.css', styles);
app.get('/assets/configuration.json', configuration);
app.get('/assets/scripts.js', new mirror(files, { minify: true }));
```

**NOTE:** Mirror loads the requested files from disk for every request. It is meant to run behind a reverse proxy that caches. You can control the cache time with `maxAge` (in seconds) in the options hash.

### Authors

- [Young Hahn](https://github.com/yhahn)
- [Konstantin Käfer](https://github.com/kkaefer)