Created
October 18, 2013 00:15
-
-
Save jfranz/7034552 to your computer and use it in GitHub Desktop.
grunt-connect-proxy config for Ember App Kit
This file contains hidden or 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
// tasks/options/connect.js | |
// add the proxy settings on the same level as your server settings | |
module.exports = { | |
server: { | |
options: { | |
port: process.env.PORT || 8000, | |
hostname: 'localhost', | |
base: 'tmp/public', | |
// Use this option to have the catch-all return a different | |
// page than index.html on any url not matching an asset. | |
// wildcard: 'not_index.html' | |
middleware: middleware | |
}, | |
}, | |
proxies: [{ | |
context: '/api', | |
host: 'localhost', | |
port: 7000, | |
changeOrigin: true, | |
rejectUnauthorized: false | |
}], | |
dist: { | |
options: { | |
port: process.env.PORT || 8000, | |
hostname: '0.0.0.0', | |
base: 'dist/', | |
middleware: middleware | |
} | |
} | |
}; | |
// add the helper to require proxyRequest | |
function middleware(connect, options) { | |
var result = [ | |
lock, | |
connect['static'](options.base), | |
connect.directory(options.base), | |
// Remove this middleware to disable catch-all routing. | |
buildWildcardMiddleware(options) | |
]; | |
// // Add connect-proxy middlware after lock middleware if enabled | |
if (Helpers.isPackageAvailable("grunt-connect-proxy")) { | |
result.splice(1,0, require("grunt-connect-proxy/lib/utils").proxyRequest); | |
} | |
// Add livereload middlware after lock middleware if enabled | |
if (Helpers.isPackageAvailable("connect-livereload")) { | |
result.splice(1,0, require("connect-livereload")()); | |
} | |
return result; | |
} |
This file contains hidden or 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
// add 'configureProxies' before 'connect:server' in the test:server and server tasks | |
grunt.registerTask('test:server', "Start a Karma test server. Automatically reruns your tests when files change and logs the results to the terminal.", [ | |
'build:debug', 'karma:server', 'configureProxies', 'connect:server', 'watch:test']); | |
grunt.registerTask('server', "Run your server in development mode, auto-rebuilding when files change.", | |
['build:debug', 'configureProxies', 'connect:server', 'watch:main']); |
This file contains hidden or 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
// tasks/helpers.js | |
// add connectProxy to the list of task requirements | |
var taskRequirements = { | |
'coffee': ['grunt-contrib-coffee'], | |
'compass': ['grunt-contrib-compass'], | |
'sass': ['grunt-sass', 'grunt-contrib-sass'], | |
'less': ['grunt-contrib-less'], | |
'stylus': ['grunt-contrib-stylus'], | |
'emberTemplates': ['grunt-ember-templates'], | |
'emblem': ['grunt-emblem'], | |
'connectProxy': ['grunt-connect-proxy'] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment