Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posting project on a server

I created a project using the Yeoman 'generator-webapp'. This includes a Grunt task named 'connect', to run the project on a server. Currently it is running on my localhost. Can anyone explain to me how I should configure this to run on a different server?

I have a server provided by my university that I can use. Let's say it's called xyz.abc.com with username myUsername and password myPassword.

The Grunt task is defined like this:

// The actual grunt server settings
connect: {
  options: {
    port: 9000,
    open: true,
    livereload: 35729,
    // Change this to '0.0.0.0' to access the server from outside
    hostname: '0.0.0.0'
  },
  livereload: {
    options: {
      middleware: function(connect) {
        return [
          connect.static('.tmp'),
          connect().use('/bower_components', connect.static('./bower_components')),
          connect.static(config.app)
        ];
      }
    }
  },
  test: {
    options: {
      open: false,
      port: 9001,
      middleware: function(connect) {
        return [
          connect.static('.tmp'),
          connect.static('test'),
          connect().use('/bower_components', connect.static('./bower_components')),
          connect.static(config.app)
        ];
      }
    }
  },
  dist: {
    options: {
      base: '<%= config.dist %>',
      livereload: false
    }
  }
},
like image 242
JNevens Avatar asked May 28 '26 18:05

JNevens


1 Answers

If you want to deploy, your app on a distant server with grunt, you can use a similar approch as I did : by adding a new deploy parameter on your yeoman build grunt task or create a new deploy dedicated task using :

  • grunt-ssh for executing linux commands over SSH and sending files over SFTP
  • grunt-zipup for ziping your local ressources before sending it through SFTP

For example, I have a build task that compiles/optimize/minify/revision resources where I added a deploy parameter :

grunt.registerTask(
    'build',
    'Build task, does everything',
    function() {

        var tasks = [
            [...], // custom build tasks
            'zipup:buildClient' // end of build generates a zip package
        ];

        if (grunt.option('deploy')) {
            tasks.push('sshexec:cleanApacheDir'); // empty remote folder for a fresh new install
            tasks.push('sftp:sendZipToApache');   // send zip through SFTP
            tasks.push('sshexec:unzipToApache');  // unzip trough SSH command `unzip`
        }

        grunt.task.run(tasks);
    }
);

See modules docs for details

ps: there are tons of other grunt plugins that you could use for that.

like image 163
Jscti Avatar answered May 31 '26 08:05

Jscti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!