Skip to content

Instantly share code, notes, and snippets.

@krzysztofantczak
Created May 12, 2013 12:27
Show Gist options
  • Save krzysztofantczak/5563387 to your computer and use it in GitHub Desktop.
Save krzysztofantczak/5563387 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var http = require('http'),
httpProxy = require('http-proxy');
// your grunt bin path (note, that for windows You need to call the target grunt file here, not its alias)
var gruntBin = 'c:/Users/Krzysiek/AppData/Roaming/npm/node_modules/grunt-cli/bin/grunt';
var cp = require('child_process');
var grunt = cp.spawn('node', [gruntBin, 'server'], {cwd: '.', env: process.env});
grunt.stdout.setEncoding('utf8');
grunt.stdout.on('data', function(data) {
console.log("%s", data)
});
grunt.stderr.setEncoding('utf8');
grunt.stderr.on('data', function(data) {
console.log("%s", data)
});
// a little timeout here, they don't want to run one after another
setTimeout(function()
{
require("supervisor").run('-w api -e js -x node app.js'.split(' '));
},2000);
// very simple proxy which does whole this magic here
httpProxy.createServer(function (req, res, proxy) {
if ( req.url.match('/components/') !== null || req.url.match('/styles/') !== null || req.url.match('/images/') !== null || req.url.match('/scripts/') !== null || req.url.match('/logic/') !== null || req.url == '/' )
{
console.log('Bouncing', req.url, 'into yeoman instance');
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 9000
});
}
else
{
console.log('Bouncing', req.url, 'into sails instance');
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 1337
});
}
}).listen(80);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment