Skip to content

Instantly share code, notes, and snippets.

@seyDoggy
Created March 28, 2014 10:43
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 seyDoggy/9829934 to your computer and use it in GitHub Desktop.
Save seyDoggy/9829934 to your computer and use it in GitHub Desktop.
Steps for sails + yeoman integrated project.
Gleaned from [krzysztofantczak](https://github.com/krzysztofantczak) in [this thread](https://github.com/yeoman/yeoman/issues/994). I'm just storing it here to play with later.
For people who want to use this combination right now, i've created a simple solution which i'm using:
1. sails new foo-project;
2. cd foo-project;
3. yo webapp (for example, note that you will have a conflict between sails and yo package.json, You can remove the sails one, and just add sails dependency into package.json from yeoman)
4. npm install && bower install
5. change your target dist directory into 'public' instead of '.tmp'
6. curl http://pastebin.com/raw.php?i=LrphmN9D > proxy.js
7. node proxy.js
8. your browser should open http://localhost (without any port by default, since proxy is listening on port 80)
9. that's all, You are using yeoman as it was before, same thing with sails - all with autoreload feature which works perfect.
@seyDoggy
Copy link
Author

In the event that this pastebin should come down, the contents are:

#!/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