@@ -34,6 +34,8 @@ const DEFAULT_OPTIONS = {
34
34
pathPrefix : "/" , // May be overridden by Eleventy, adds a virtual base directory to your project
35
35
watch : [ ] , // Globs to pass to separate dev server chokidar for watching
36
36
aliases : { } , // Aliasing feature
37
+ rebuildUrl : null , // POST URL to trigger rebuild
38
+ rebuildUrlToken : "" , // Secret token in x-11ty-rebuild-token header
37
39
indexFileName : "index.html" , // Allow custom index file name
38
40
useCache : false , // Use a cache for file contents
39
41
headers : { } , // Set default response headers
@@ -117,6 +119,10 @@ class EleventyDevServer {
117
119
this . options . pathPrefix = this . cleanupPathPrefix ( this . options . pathPrefix ) ;
118
120
}
119
121
122
+ setEventBus ( _eventBus ) {
123
+ this . eventBus = _eventBus ;
124
+ }
125
+
120
126
get watcher ( ) {
121
127
if ( this . #watcher) {
122
128
return this . #watcher;
@@ -481,6 +487,18 @@ class EleventyDevServer {
481
487
return res . end ( "" ) ;
482
488
}
483
489
490
+ if ( this . options . rebuildUrl && req . url === this . options . rebuildUrl && req . method === 'POST' ) {
491
+ const token = req . headers [ 'x-11ty-rebuild-token' ] ;
492
+ if ( token !== this . options . rebuildUrlToken ) {
493
+ res . writeHead ( 403 , { 'Content-Type' : 'text/plain' } ) ;
494
+ return res . end ( 'Forbidden' ) ;
495
+ }
496
+
497
+ this . eventBus . emit ( 'eleventyDevServer.rebuild' ) ;
498
+ res . writeHead ( 200 ) ;
499
+ return res . end ( ) ;
500
+ }
501
+
484
502
for ( let urlPatternString in this . options . onRequest ) {
485
503
let fn = this . options . onRequest [ urlPatternString ] ;
486
504
let fullPath = this . getServerPath ( urlPatternString ) ;
0 commit comments