I was going to ask how this could be done, but managed to dot it myself after a bit of searching and fumbling with npm.
The short version is, put this stuff in a package.json file in the folder where you run caddy. Set the template path and run npm install, then npm watch and npm serve
{
"name": "caddy-livetemplate",
"author": "Ville Vanninen",
"description": "Reloads caddy templates any time they change. Run both `npm run watch` & `npm run serve`. Combining them to `npm start` caused caddy to panic, that's why the separate commands.",
"watch": {
"reload": "server/pumpula6/template.html"
},
"scripts": {
"watch": "npm-watch",
"reload": "cat caddy.pid | xargs -I pidnum kill -s USR1 pidnum",
"serve": "caddy -pidfile caddy.pid"
},
"license": "CC0",
"devDependencies": {
"npm-watch": "^0.1.8"
}
}
There’s probably some simpler way to do this, but hey, I got this working.
The serve task tells caddy to run and output a pidfile so we can command it later.
npm-watch watches the template file and runs the reload task whenever the template changes.
The reload task reads the pidfile and commands the matching caddy instance to reload configs.
I tried doing a "start": "npm run serve & npm run watch" task in the scripts section, but caddy paniced when running that way. Anyone know why that could be?
Parhelia:server sakamies$ npm start
> caddy-livetemplate@ start /Users/sakamies/Dropbox/Projects/sites/pumpula.net/server
> npm run watch & npm run serve
> caddy-livetemplate@ serve /Users/sakamies/Dropbox/Projects/sites/pumpula.net/server
> caddy -pidfile caddy.pid
> caddy-livetemplate@ watch /Users/sakamies/Dropbox/Projects/sites/pumpula.net/server
> npm-watch
Activating privacy features... done.
[reload] [nodemon] 1.11.0
panic: runtime error: index out of range
goroutine 9 [running]:
panic(0x59a720, 0xc420012190)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/mholt/caddy.trapSignalsPosix.func1()
/tmp/custombuild_1790_518258033/src/github.com/mholt/caddy/sigtrap_posix.go:52 +0x79a
created by github.com/mholt/caddy.trapSignalsPosix
/tmp/custombuild_1790_518258033/src/github.com/mholt/caddy/sigtrap_posix.go:83 +0x35
npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "serve"
npm ERR! node v6.2.2
npm ERR! npm v3.9.6
npm ERR! code ELIFECYCLE
npm ERR! caddy-livetemplate@ serve: `caddy -pidfile caddy.pid`
npm [reload] [nodemon] clean exit - waiting for changes before restart
ERR! Exit status 2
npm ERR!
npm ERR! Failed at the caddy-livetemplate@ serve script 'caddy -pidfile caddy.pid'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the caddy-livetemplate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! caddy -pidfile caddy.pid
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs caddy-livetemplate
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls caddy-livetemplate
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/sakamies/Dropbox/Projects/sites/pumpula.net/server/npm-debug.log
npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.2.2
npm ERR! npm v3.9.6
npm ERR! code ELIFECYCLE
npm ERR! caddy-livetemplate@ start: `npm run watch & npm run serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the caddy-livetemplate@ start script 'npm run watch & npm run serve'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the caddy-livetemplate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run watch & npm run serve
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs caddy-livetemplate
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls caddy-livetemplate
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/sakamies/Dropbox/Projects/sites/pumpula.net/server/npm-debug.log
Parhelia:server sakamies$ ==> Successfully started `php56` (label: homebrew.mxcl.php56)
Yep, that’s a bug. Looks like initiating a reload before Caddy has “saved” a handle for the instance of the running server. I just replicated it locally and will have a fix out soon. Thanks!