Open utilityboy opened 10 years ago
Is there an answer to this question. I'm stuck on this, too.
+1
Hello,
I don't know if this could help, but in one project I got it working adding a "proxies" property to dist configuration :
dist: {
options: {
open: true,
base: '<%= yeoman.dist %>',
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));
});
return middlewares;
}
},
proxies: proxies
}
where proxies is a shared array between "dist" and "livereload".
HI @zimbrecka, Can you add an example for "proxies" ?. I try this add the next code in dist configuration.
dist: {
options: {
open: true,
base: '<%= yeoman.dist %>',
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));
});
return middlewares;
}
},
proxies: [{
context: '/api',
host: 'localhost',
port: 3000
// changeOrigin: true
}]
}
But I can't fix this. Someone has been able to fix them ?
Hello @patojimenez, for sure I can (we load our Grunt config w/ load-grunt-config) :
require('load-grunt-config')(grunt, {
configPath: path.join(process.cwd(), 'grunt/configs'),
data: {
...
remoteHost: 'backoffice.project-dev.fr',
proxies: [
{
context: '/api',
host: '<%= remoteHost %>',
port: 80,
https: false,
changeOrigin: true,
xforward: false,
headers: {
'host': '<%= remoteHost %>'
}
},...
Thanks a lot @zimbrecka, it works for me.
Happy I could help !
@zimbrecka have you an email contact ?, For some reason after run "grunt build" and create dist directory in my server appear and error 403. How can I check if the proxies settings are in my compiled js ?.
remember to add configureProxies before connect task:
1) update dist options
dist: {
options: {
open: true,
middleware: function (connect, options) {
var middlewares = [connect.static(appConfig.dist)];
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
// Setup the proxy
middlewares.push(require('grunt-connect-proxy/lib/utils').proxyRequest);
// Serve static files
options.base.forEach(function(base) {
middlewares.push(connect.static(base));
});
return middlewares;
}
}
}
2) update tasks
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
if (target === 'dist') {
return grunt.task.run([
'build',
'configureProxies:server', // added just before connect
'connect:dist:keepalive'
]);
}
grunt.task.run([
'clean:server',
'wiredep',
'concurrent:server',
'postcss:server',
'configureProxies:server', // added just before connect
'connect:livereload',
'watch'
]);
});
Hello,
This may be a somewhat of a silly question, but I haven't been able to come up with the proper configuration to allow proxying for a dist target. I have an angular app based on yeoman's angular generators and would like to test some aspects of the dist target without deploying the entire application.
My understanding of Grunt is somewhat limited, but wanted to ask the if this was in fact possible without proceeding down a rabbit hole.
Many thanks.
connect task:
actual grunt task