From 92e1dcdd3eada3691a9a75ba995757b8ba3eda3a Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 30 May 2014 19:24:38 +0200 Subject: [PATCH] Proxy for api calls. --- Gruntfile.js | 40 ++++++++++++++++++++++++++++------------ package.json | 1 + 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index d62e415..ae34016 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -57,8 +57,32 @@ module.exports = function (grunt) { port: 9000, // Change this to '0.0.0.0' to access the server from outside. hostname: 'localhost', - livereload: 35729 + livereload: 35729, + middleware: function (connect, options) { + if (!Array.isArray(options.base)) { + options.base = [options.base]; + } + + // Setup the proxy + var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest]; + + // Serve static files. + options.base.forEach(function(base) { + middlewares.push(connect.static(base)); + }); + + // Make directory browse-able. + var directory = options.directory || options.base[options.base.length - 1]; + middlewares.push(connect.directory(directory)); + + return middlewares; + } }, + proxies: [{ + context: '/api/', + host: '127.0.0.1', + port: 8080 + }], livereload: { options: { open: true, @@ -75,14 +99,6 @@ module.exports = function (grunt) { } }, - // The node-server settings - develop: { - server: { - file: 'server/main.js', - nodeArgs: ['--debug'] - } - }, - // Make sure code styles are up to par and there are no obvious mistakes jshint: { options: { @@ -353,16 +369,16 @@ module.exports = function (grunt) { grunt.registerTask('serve', function (target) { if (target === 'dist') { - return grunt.task.run(['build', 'develop', 'connect:dist:keepalive']); + return grunt.task.run(['build', 'connect:dist:keepalive']); } - grunt.task.run([ + return grunt.task.run([ 'clean:server', 'bowerInstall', 'concurrent:server', 'autoprefixer', + 'configureProxies', 'connect:livereload', - 'develop', 'watch' ]); }); diff --git a/package.json b/package.json index 30445fc..25629ee 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "grunt-autoprefixer": "~0.4.0", "grunt-bower-install": "~1.0.0", "grunt-concurrent": "~0.5.0", + "grunt-connect-proxy": "~0.1.10", "grunt-contrib-clean": "~0.5.0", "grunt-contrib-compass": "~0.7.2", "grunt-contrib-concat": "~0.3.0",