Skip to content

Instantly share code, notes, and snippets.

@dbismut
Last active September 6, 2015 10:21
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 dbismut/78c7cb7d97b1927a9cea to your computer and use it in GitHub Desktop.
Save dbismut/78c7cb7d97b1927a9cea to your computer and use it in GitHub Desktop.
/**
* React Starter Kit (http://www.reactstarterkit.com/)
*
* Copyright © 2014-2015 Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
import path from 'path';
import cp from 'child_process';
import gaze from 'gaze';
/**
* Launches Node.js/Express web server in a separate (forked) process.
*/
export default () => new Promise((resolve, reject) => {
console.log('serve');
let started = false;
let server = (function startup() {
const child = cp.fork('build/server.js', {
env: Object.assign({NODE_ENV: 'development'}, process.env)
});
child.once('message', message => {
if (message.match(/^online$/)) {
if (!started) {
started = true;
gaze('./build/server.js', function(err, watcher) {
this.on('all', (event, filepath) => {
console.log('Restarting development server.');
server.kill('SIGTERM');
server = startup();
});
});
resolve();
}
}
});
child.once('error', err => reject(error));
return child;
})();
process.on('exit', () => server.kill('SIGTERM'));
});
@koistya
Copy link

koistya commented Sep 3, 2015

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment