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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With