Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support rebuild event from dev server #70

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

antgel
Copy link

@antgel antgel commented Oct 30, 2023

This feature adds the ability to define a rebuildUrl in the config. When eleventy-dev-server is running and a POST request is made to that URL, 11ty rebuilds the site.

Usage:

  eleventyConfig.setServerOptions({
    rebuildUrl: "/rebuild/",
    rebuildUrlToken: "foobar",
  });

...

$ curl -vsSo/dev/null -X POST http://localhost:8080/rebuild/
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /rebuild/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 403 Forbidden
< Content-Type: text/plain
< Date: Mon, 30 Oct 2023 11:43:04 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< Transfer-Encoding: chunked
< 
{ [19 bytes data]
* Connection #0 to host localhost left intact

$ curl -vsSo/dev/null -X POST -H 'x-11ty-rebuild-token: foobar' http://localhost:8080/rebuild/
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /rebuild/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.81.0
> Accept: */*
> x-11ty-rebuild-token: foobar
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Mon, 30 Oct 2023 11:43:20 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< Transfer-Encoding: chunked
< 
{ [5 bytes data]
* Connection #0 to host localhost left intact

Rationale: I'm working on a cool 11ty / Strapi project. In the cloud, when content is updated on Strapi, Strapi can send a webhook to whichever service is hosting 11ty, to rebuild the 11ty site. However this doesn't work for local development, as discussed at 11ty/eleventy#604, 11ty/eleventy#691, 11ty/eleventy#1198, 11ty/eleventy#1358, and elsewhere.

There have been suggested workarounds that generally involve the 11ty user writing an(other) HTTP server to accept the request and dumping a file somewhere to trigger a rebuild. But it is clunky and we already have an HTTP server. I reused existing EventBus functionality; really most of my time was spent reading and understanding the code.

I hope this is useful; it's my first 11ty contribution so feel free to let me know how it may be improved. :)

Corresponding 11ty PR: 11ty/eleventy#3085

Please review the commits separately, one is mere formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant