I want to proxy http://localhost:9000/images and http://localhost:9000/rest to https://remotehost/images and https://remotehost/rest but I get error 500 for both. What am I doing wrong? How to debug this? Here is my config:
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
proxies: [
{
context: '/images',
host: remotehost,
port: 443,
https: true,
changeOrigin: true,
xforward: false,
rejectUnauthorized: false
}
],
livereload: {
options: {
open: true,
base: [
'.tmp',
'<%= yeoman.app %>'
],
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;
}
}
},
I tried to debug this running grunt serve --debug bug I get no extra information about why I get this error. Thank you! https://github.com/gruntjs/grunt-contrib-connect/issues/176
The package grunt-connect-proxy
seems to be abandoned: see https://github.com/drewzboto/grunt-connect-proxy/issues/144
I run a successfull configuration using grunt-connect-proxy2 in the following way:
{ /* package.json */
"name": "grunt-connect-sample",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-connect-proxy2": "^2.0.0",
"grunt-contrib-connect": "^1.0.2",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-watch": "^1.0.0"
}
}
then the Gruntfile.js
is:
module.exports = function (grunt) {
grunt.initConfig({
jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
options: {
globals: {
jQuery: true
}
}
},
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
},
connect: {
server: {
options: {
port: 9000,
base: 'src/webroot',
keepalive: true,
middleware: function (connect, options, defaultMiddleware) {
var proxy = require('grunt-connect-proxy2/lib/utils').proxyRequest;
return [
// Include the proxy first
proxy
].concat(defaultMiddleware);
}
},
proxies: [
{
context: '/google',
host: 'www.google.it',
port: 443,
https: true,
rewrite: {
'^/google': ''
}
}
]
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-connect-proxy2');
grunt.registerTask('default', ['jshint', 'configureProxies:server', 'connect:server']);
};
then you cann access http://localhost:9000/google
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With