Skip to content

Instantly share code, notes, and snippets.

@daviddarnes
Created January 9, 2020 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daviddarnes/ff765e7174aad73da2623c2e63099ed8 to your computer and use it in GitHub Desktop.
Save daviddarnes/ff765e7174aad73da2623c2e63099ed8 to your computer and use it in GitHub Desktop.
Mini Node server for triggering 11ty builds
const http = require('http');
const process = require('process');
const { exec } = require('child_process');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
console.log('Ghost content updated!');
process.chdir('../eleventy/');
console.log(`Navigated to: ${process.cwd()}`);
exec('eleventy build', (error, output, ouputerror) => {
console.log('Attempting 11ty build…')
if (error !== null) {
console.log('Build failed…')
console.log(`exec error: \n${error}`);
}
console.log(`exec output: \n${output}`);
console.log(`exec output errors: \n${ouputerror ? ouputerror : 'there were no errors'}`);
})
res.end('okay');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment