grunt-connect-proxy
grunt-connect-proxy copied to clipboard
proxy does not forward {post, patch, put} requests
so i have my back end service receiving proxy forwards at /api/0.1. my connect config looks like this:
connect: {
options: {
port: 9000,
hostname: "localhost",
livereload: 35729,
},
proxies: [
{
context: "/api/0.1",
host: "localhost",
port: 8000
},
],
livereload: {
options: {
open: true,
base: "<%= yeoman.app %>",
keepAlive: true,
debug: true,
middleware: function(connect, options, middlewares) {
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest,
rewriteModule = require('http-rewrite-middleware');
options.base.forEach(function(base) {
middlewares.push(connect.static(base));
});
middlewares.push(connect().use(
"/bower_components",
connect.static("./bower_components")
));
middlewares.push(proxySnippet);
middlewares.unshift(rewriteModule.getMiddleware([
{from : "^/static/(.*)", to: "/$1"}
]));
return middlewares;
}
}
}
}
connect is successfully reaching the api backend on GET requests exclusively, while logging [D] server POST /api/0.1/login/ 405 0 - 0.183 ms
on any POST PUT PATCH requests before sending the request to the api backend (the backend is never sent the request).
i have tried adding changeOrigin: true, https: false, xforward: false
to the proxy config with the same results.
does any one know what is going on and how i can fix this?
+1, met the same issue, tried below two suggestions, but failed.
http://stackoverflow.com/questions/25137981/rewrite-cookie-paths-when-using-grunt-connect-proxy https://coderwall.com/p/bwrb1w/enable-post-rest-requests-in-grunt-contrib-connect
Had the same problem but turns out it is the order of the middlewares. In my case this did the trick:
middleware: function (connect, options, middlewares) { middlewares.unshift(require("grunt-connect-proxy/lib/utils").proxyRequest); middlewares.unshift(require("http-rewrite-middleware").getMiddleware( [ {from: "^/gat/(.*)$", to: "/$1"} ], { verbose: false })); return middlewares; }