This repository was archived by the owner on Jun 24, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const express = require ( 'express' ) ;
4
+ const Assets = require ( '../' ) ;
4
5
const app = express ( ) ;
5
6
6
- const Assets = require ( '../' ) ;
7
+ // set up asset bundler
7
8
const assets = new Assets ( './assets/es5/main.js' ) ;
8
9
10
+ // listen for events
9
11
assets . on ( 'update' , ( ids ) => {
10
12
ids . forEach ( ( id ) => {
11
13
console . log ( 'updated:' , id ) ;
12
14
} ) ;
13
15
} ) ;
14
16
17
+ // provide bundle info to each request
18
+ app . use ( assets . middelware ( ) ) ;
19
+
20
+ // attach bundle routes
15
21
app . use ( assets . router ( ) ) ;
16
22
23
+ // print where bundle is
24
+ app . get ( '/' , ( req , res , next ) => {
25
+ res . status ( 200 ) . send ( `JS bunde is at: ${ res . locals . js } ` ) ;
26
+ } )
27
+
28
+ // start server
17
29
const server = app . listen ( 8080 , ( ) => {
18
30
console . log ( `http server - Bundle at: http://localhost:${ server . address ( ) . port } /js/` ) ;
19
31
} ) ;
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ module.exports = class Middleware extends EventEmitter {
16
16
cache : { } ,
17
17
packageCache : { } ,
18
18
debug : true ,
19
- jsBundlePath : '/js' ,
19
+ jsPath : '/js' ,
20
20
} , options ) ;
21
21
22
22
this . emits = emits ;
@@ -44,7 +44,8 @@ module.exports = class Middleware extends EventEmitter {
44
44
this . app = express . Router ( { // eslint-disable-line
45
45
mergeParams : true ,
46
46
} ) ;
47
- this . app . get ( this . options . jsBundlePath , this . js ( ) ) ;
47
+
48
+ this . app . get ( this . options . jsPath , this . js ( ) ) ;
48
49
}
49
50
50
51
@@ -58,6 +59,14 @@ module.exports = class Middleware extends EventEmitter {
58
59
}
59
60
60
61
62
+ middelware ( jsProp = 'js' ) {
63
+ return ( req , res , next ) => {
64
+ res . locals [ jsProp ] = this . options . jsPath ;
65
+ next ( ) ;
66
+ }
67
+ }
68
+
69
+
61
70
router ( ) {
62
71
return this . app ;
63
72
}
You can’t perform that action at this time.
0 commit comments