Last active
September 6, 2015 10:21
-
-
Save dbismut/78c7cb7d97b1927a9cea to your computer and use it in GitHub Desktop.
serve.js updated for automatic server restart on React-Starter-Kit based on https://github.com/kriasoft/react-starter-kit/blob/ebbce5aed8f3efa9315abaec302cd1060d609a95/gulpfile.babel.js#L115-L137
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍