Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yeoman + angularjs + restify

I've written an API using restify. Now I'm developing a webapp with angular, using yeoman workflow.

I can run two servers, one for restify "localhost:3000" and one for the ui "localhost:3001".

But I need only one server, better if managed by yeoman. I guess it's possible to put a "proxy" which redirect all requests to localhost:3001/api to localhost:3000/api, but having only one server is preferable.

like image 504
Alessandro Pezzato Avatar asked Mar 19 '26 06:03

Alessandro Pezzato


1 Answers

I got it working adding a new task to Gruntfile.js:

  grunt.registerTask('server', 'Start a custom web server.', function() {
    grunt.task.run([
      'clean:server',
      'bower-install',
      'concurrent:server',
      'autoprefixer',
      'watch'
    ]);
    var server = require('./app.js');
    server.use(require('connect-livereload')({
      port: 35729
    }));
    server.get(/^\/.*$/, require('restify').serveStatic({
        'directory' : 'app',
        'default' : 'index.html'
    }));
    server.listen(9000);
  });

app.js is where restify is initialized, I had to add this line at the end:

module.exports = server;
like image 121
Alessandro Pezzato Avatar answered Mar 21 '26 22:03

Alessandro Pezzato



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!