Reputation: 64
I need a proxy to interact with some external APIs during development. I fumbled around with grunt-connect-proxy, but beeing a Grunt noobie, i failed getting it to work inside ember-app-kit's Gruntfile or options/connect.js file.
Assuming that needing a proxy in development would be a rather common task, can somebody show an example of how to setup a proxy inside ember-app-kit?
Upvotes: 0
Views: 608
Reputation: 46
Assuming you have installed grunt-connect-proxy (npm install grunt-connect-proxy --save-dev
)
In Gruntfile.js add 'configureProxies' before 'connect:server' in the test:server and server tasks
grunt.registerTask('server', "Run your server in development mode, auto-rebuilding when files change.",
['build:debug', 'configureProxies', 'connect:server', 'watch:main']);
Add the following to taskRequirements in tasks/helpers.js
'connectProxy': ['grunt-connect-proxy']
In tasks/options/connect.js add the proxy settings on the same level as your server settings
// example settings to proxy to a dev server
proxies: [{
context: '/api',
host: 'localhost',
port: 7000,
changeOrigin: true,
rejectUnauthorized: false
}],
In the same file, add the following to require the proxyRequest in the middleware function
if (Helpers.isPackageAvailable("grunt-connect-proxy")) {
result.splice(1,0, require("grunt-connect-proxy/lib/utils").proxyRequest);
}
See https://gist.github.com/jfranz/7034552 for a more complete example.
Upvotes: 2