Last active
August 29, 2015 14:02
-
-
Save aaronshaf/0f4b4cfe99bbd328f236 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const cp = require('child_process') | |
| const http = require('http') | |
| const httpProxy = require('http-proxy') | |
| const Promise = require('rsvp').Promise | |
| const PROXY_PORT = 4201 | |
| const BROCCOLI_PORT = 4200 | |
| function startBroccoli() { | |
| return new Promise(function(resolve,reject) { | |
| console.log('Starting Broccoli') | |
| const broccoli = cp.spawn('node_modules/.bin/broccoli',['serve']) | |
| broccoli.stdout.setEncoding('utf8') | |
| broccoli.stdout.on("close", resolve) | |
| broccoli.stdout.on("data", function(data) { | |
| console.log(data) | |
| if(data.indexOf('Serving on') !== -1) { | |
| console.log('Broccoli started') | |
| resolve() | |
| } | |
| }) | |
| }) | |
| } | |
| function startProxy() { | |
| return new Promise(function(resolve,reject) { | |
| const proxy = httpProxy.createProxyServer({}) | |
| const server = http.createServer(function(req, res) { | |
| const isNotStaticResource = req.url.indexOf('.') === -1 | |
| if(isNotStaticResource) { | |
| req.url = 'http://localhost:' + PROXY_PORT + '/' | |
| } | |
| proxy.web(req, res, { target: 'http://localhost:' + BROCCOLI_PORT }) | |
| }) | |
| server.listen(PROXY_PORT) | |
| console.log('Proxy is listening on port ' + PROXY_PORT) | |
| }) | |
| } | |
| startBroccoli().then(startProxy) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment