Skip to content

Commit

Permalink
Restart Netlify CMS proxy server on astro.config reload (#38)
Browse files Browse the repository at this point in the history
When astro.config is saved, Astro automatically reloads, which caused a second instance of netlify-cms-proxy-server to try to start and crash. This fix ensures we kill and restart the proxy server instead each time this happens.
  • Loading branch information
delucis committed Oct 31, 2022
1 parent 571ab8d commit 9b2802c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sixty-carpets-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-netlify-cms": patch
---

Restart Netlify CMS proxy server when astro.config reloads
8 changes: 7 additions & 1 deletion integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export default function NetlifyCMS({
adminPath = adminPath.slice(0, -1);
}

let proxy: ReturnType<typeof spawn>;

const NetlifyCMSIntegration: AstroIntegration = {
name: 'netlify-cms',
hooks: {
Expand Down Expand Up @@ -73,13 +75,17 @@ export default function NetlifyCMS({
},

'astro:server:start': () => {
const proxy = spawn('netlify-cms-proxy-server', {
proxy = spawn('netlify-cms-proxy-server', {
stdio: 'inherit',
// Run in shell on Windows to make sure the npm package can be found.
shell: process.platform === 'win32',
});
process.on('exit', () => proxy.kill());
},

'astro:server:done': () => {
proxy.kill();
},
},
};
return [react(), NetlifyCMSIntegration];
Expand Down

0 comments on commit 9b2802c

Please sign in to comment.