Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple proxies running at the same time #109

Open
pawelphilipczyk opened this issue Jun 19, 2015 · 5 comments
Open

Multiple proxies running at the same time #109

pawelphilipczyk opened this issue Jun 19, 2015 · 5 comments
Labels

Comments

@pawelphilipczyk
Copy link

I configured browsersync with Grunt to run two proxy instances at the same time. The reason for that is I need both http and https running. This was working just fine up untill recently when I updated npm.
The error I'm getting now is: Warning: Instance: Grunt is already running! Use --force to continue.
M setup looks like that:

browserSync: {
    http: {
        bsFiles: {
            src: [
                'css/*.css'
            ]
        },
        options: {
            watchTask: true,
            injectChanges: true,
            open: false,
            port: 3001,
            ui: {
                port: 3011
            },
            proxy: 'http://' + config.host + '.local:9001/' + config.path
        }
    },
    https: {
        bsFiles: {
            src: [
                'css/*.css'
            ]
        },
        options: {
            watchTask: true,
            injectChanges: true,
            open: false,
            port: 3002,
            ui: {
                port: 3012
            },
            proxy: 'https://' + config.host + '.local:9002/' + config.path
        }
    }
}

and then I just run it like that: grunt.registerTask('default', [ 'browserSync', 'watch' ]);

Thanks for any advice!

@shakyShane
Copy link
Contributor

Looks like a bug - thanks for reporting we will look at this asap.

@shakyShane shakyShane added the bug label Jun 19, 2015
@jaumesalatantinya
Copy link

I have de same problem.

Is there any way to run multiple proxies using bs-config.js runing as command line?

@oxocode
Copy link

oxocode commented Nov 19, 2015

+1 here...

@fabiofabbrucci
Copy link

+1

@WinfieldHill
Copy link

Adding my fix, since I haven't found a nice resolution for this bug (wiring two server configs within my browserSync tasks with Node 5.0.0 as my Engine) and I received the same error as others in this issue. For now, I've resorted to an imperative implementation and it's working fine (no proxies right now, just 2 instances for HTTP and HTTPS).

module.exports = function(grunt) {
  grunt.registerTask('syncClient', 'start server on multiple ports for http and https', function(target) {
    var
       lodash = require('lodash')
      ,app = grunt.config.data.paths.app
      ,optionsBase = {
         notify: false
        ,background: true
        ,watchOptions: {
          ignored: ''
        }
      }
      ,optionsLiveReload = {
        files : [
           app + '/{,*/}*.html'
          ,app + '/images/{,*/}*'
          ,app + '/scripts/*.js'
          ,'.tmp/styles/css/{,*/}*.css'
          ,'.tmp/styles/less/{,*/}*.less'
          ,'.tmp/scripts/{,*/}*.js'
        ]
        ,port: 9000
        ,server: {
           baseDir: ['.tmp', 'app']
          ,routes: {'/bower_components': './bower_components'
          }
        }
        ,plainAndSecure: true
      }
      ,optionsTest = {
         open: false
        ,logLevel: 'silent'
        ,host: 'localhost'
        ,port: 9001
        ,server: {
           baseDir: ['.tmp', './test', 'app']
          ,routes: {
            '/bower_components': './bower_components'
          }
        }
      }
      ,optionsDist = {
        background: false
        ,server: 'dist'
        ,plainAndSecure: true
      };

    function startHTTPSWatch(options) {
      var
         httpsOptions = lodash.cloneDeep(options)
        ,bs2 = require("browser-sync").create('HTTPS');

      lodash.extend(httpsOptions, {ui: {port: 3002}, port: 9009, https: true});

      bs2.init(httpsOptions, function(err, bs) {
        grunt.log.writeln('is bs2 active: ' + bs2.active);
      });
    };

    function initBrowserWatch(options) {
      var bs1 = require("browser-sync").create('HTTP');

      bs1.init(options, function(err, bs) {
        grunt.log.writeln('is bs1 active: ' + bs1.active);
      });

      if (options.plainAndSecure) { startHTTPSWatch.call(this, options); }
    };

    if (target === 'livereload') {
        initBrowserWatch.call(this, lodash.extend(optionsBase, optionsLiveReload));
    } else if (target === 'test') {
        initBrowserWatch.call(this, lodash.extend(optionsBase, optionsTest));
    } else if (target === 'dist') {
        initBrowserWatch.call(this, lodash.extend(optionsBase, optionsDist));
    }
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants