Last active
September 6, 2016 05:45
-
-
Save gbabiars/6149943 to your computer and use it in GitHub Desktop.
Grunt Connect Server with Proxies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest; | |
module.exports = function(grunt) { | |
grunt.initConfig({ | |
watch: { | |
all: { | |
files: ['Gruntfile.js'] | |
} | |
}, | |
connect: { | |
'static': { | |
options: { | |
hostname: 'localhost', | |
port: 8001 | |
} | |
}, | |
server: { | |
options: { | |
hostname: 'localhost', | |
port: 8000, | |
middleware: function(connect) { | |
return [proxySnippet]; | |
} | |
}, | |
proxies: [ | |
{ | |
context: '/svc', | |
host: 'myserviceshost', | |
port: 8080 | |
}, | |
{ | |
context: '/api', | |
host: 'myapihost', | |
port: 9080 | |
}, | |
{ | |
context: '/', | |
host: 'localhost', | |
port: 8001 | |
} | |
] | |
}, | |
fakeServer: { | |
options: { | |
hostname: 'localhost', | |
port: 8000, | |
middleware: function(connect) { | |
return [proxySnippet]; | |
} | |
}, | |
proxies: [ | |
{ | |
context: '/svc', | |
host: 'localhost', | |
port: 8080 | |
}, | |
{ | |
context: '/api', | |
host: 'localhost', | |
port: 9080 | |
}, | |
{ | |
context: '/', | |
host: 'localhost', | |
port: 8001 | |
} | |
] | |
} | |
} | |
}); | |
grunt.loadNpmTask('grunt-contrib-watch'); | |
grunt.loadNpmTask('grunt-contrib-connect'); | |
grunt.loadNpmTask('grunt-connect-proxy'); | |
grunt.registerTask('server', ['connect:static', 'configureProxies:server', 'connect:server', 'watch']); | |
grunt.registerTask('fakeServer', ['connect:static', 'configureProxies:fakeServer', 'connect:fakeServer', 'watch']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should grunt.loadNpmTask be grunt.loadNpmTasks instead?
Fork with suggested update here:
https://gist.github.com/amenzies/8047326