-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (28 loc) · 968 Bytes
/
index.js
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
// koa-manifest-rev
// Copyright (c) 2016- Nick Baugh <[email protected]>
// MIT Licensed
// * Author: [@niftylettuce](https://twitter.com/#!/niftylettuce)
// * Source: <https://github.com/niftylettuce/koa-manifest-rev>
// # koa-manifest-rev
module.exports = function(opts) {
if (typeof opts !== 'object') {
throw new TypeError('`options` argument required');
}
if (typeof opts.manifest !== 'string') {
throw new TypeError('`manifest` property is required');
}
if (typeof opts.prepend !== 'undefined' && typeof opts.prepend !== 'string') {
throw new TypeError('`prepend` property defined, but it was not a string');
}
opts.prepend = opts.prepend || '/';
return function(ctx, next) {
ctx.state.manifest = str => {
let output = opts.prepend + str;
try {
output = opts.prepend + (require(opts.manifest)[str] || str);
} catch (err) {}
return output;
};
return next();
};
};