File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,21 @@ Generate a short (7-digit) md5 hash instead of the full (32-digit) one.
5959* Type: Boolean
6060* Default: ` true `
6161
62+ ### pathPrefix
63+
64+ If you are using the staticify convenience middleware through a specific route, it is necessary to indicate the route in this option.
65+
66+ * Type: String
67+ * Default: "/"
68+
69+ ``` js
70+ var path = require (' path' );
71+ var options = { pathPrefix: ' /assets' };
72+ var staticify = require (' staticify' )(path .join (__dirname , ' public' ), options);
73+
74+ app .use (' /assets' , staticify .middleware ); // `app` is your express instance
75+ ```
76+
6277### sendOptions
6378
6479* Type: Object
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ const staticify = (root, options) => {
1717 let defaultOptions = {
1818 includeAll : opts . includeAll || false ,
1919 shortHash : opts . shortHash || true ,
20+ pathPrefix : opts . pathPrefix || '/' ,
2021 sendOptions : opts . sendOptions || { }
2122 } ;
2223
@@ -74,7 +75,7 @@ const staticify = (root, options) => {
7475
7576 fileNameParts . push ( versions [ p ] , fileNameParts . pop ( ) ) ;
7677
77- return path . posix . join ( path . dirname ( p ) , fileNameParts . join ( '.' ) ) ;
78+ return path . posix . join ( opts . pathPrefix , path . dirname ( p ) , fileNameParts . join ( '.' ) ) ;
7879 } ;
7980
8081 // index.<hash>.js -> index.js
Original file line number Diff line number Diff line change @@ -60,6 +60,17 @@ describe('.getVersionedPath', () => {
6060 / ^ [ 0 - 9 a - f ] { 32 } $ / i. exec ( versioned [ 1 ] ) [ 0 ] . should . equal ( versioned [ 1 ] ) ;
6161 } ) ;
6262
63+ it ( 'should add a prefix route to the path' , ( ) => {
64+ let versioned = staticify ( ROOT , { pathPrefix : '/prefix' } ) . getVersionedPath ( '/index.js' ) ;
65+
66+ versioned = versioned . split ( '.' ) ;
67+ versioned . should . have . a . lengthOf ( 3 ) ;
68+ versioned [ 0 ] . should . equal ( '/prefix/index' ) ;
69+ versioned [ 2 ] . should . equal ( 'js' ) ;
70+ versioned [ 1 ] . should . have . a . lengthOf ( 7 ) ;
71+ / ^ [ 0 - 9 a - f ] { 7 } $ / i. exec ( versioned [ 1 ] ) [ 0 ] . should . equal ( versioned [ 1 ] ) ;
72+ } ) ;
73+
6374 it ( 'shouldn\'t add a hash if the path isn\'t known' , ( ) => {
6475 staticify ( ROOT ) . getVersionedPath ( '/unknown.js' ) . should . equal ( '/unknown.js' ) ;
6576 } ) ;
You can’t perform that action at this time.
0 commit comments