{"action":"created","issue":{"url":"https://api.github.com/repos/vuejs/vue-cli/issues/1856","repository_url":"https://api.github.com/repos/vuejs/vue-cli","labels_url":"https://api.github.com/repos/vuejs/vue-cli/issues/1856/labels{/name}","comments_url":"https://api.github.com/repos/vuejs/vue-cli/issues/1856/comments","events_url":"https://api.github.com/repos/vuejs/vue-cli/issues/1856/events","html_url":"https://github.com/vuejs/vue-cli/issues/1856","id":341293197,"node_id":"MDU6SXNzdWUzNDEyOTMxOTc=","number":1856,"title":"Proxy changeOrigin default is wrong","user":{"login":"tecoholic","id":383862,"node_id":"MDQ6VXNlcjM4Mzg2Mg==","avatar_url":"https://avatars1.githubusercontent.com/u/383862?v=4","gravatar_id":"","url":"https://api.github.com/users/tecoholic","html_url":"https://github.com/tecoholic","followers_url":"https://api.github.com/users/tecoholic/followers","following_url":"https://api.github.com/users/tecoholic/following{/other_user}","gists_url":"https://api.github.com/users/tecoholic/gists{/gist_id}","starred_url":"https://api.github.com/users/tecoholic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tecoholic/subscriptions","organizations_url":"https://api.github.com/users/tecoholic/orgs","repos_url":"https://api.github.com/users/tecoholic/repos","events_url":"https://api.github.com/users/tecoholic/events{/privacy}","received_events_url":"https://api.github.com/users/tecoholic/received_events","type":"User","site_admin":false},"labels":[{"id":915272558,"node_id":"MDU6TGFiZWw5MTUyNzI1NTg=","url":"https://api.github.com/repos/vuejs/vue-cli/labels/feat:%20cli-service%20serve","name":"feat: cli-service serve","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-15T05:20:03Z","updated_at":"2018-07-15T15:04:00Z","closed_at":null,"author_association":"NONE","body":"### Version\r\n3.0.0-rc.3\r\n\r\n### Reproduction link\r\n[https://jsfiddle.net/tecoholic/y76qcsha/](https://jsfiddle.net/tecoholic/y76qcsha/)\r\n\r\n### Steps to reproduce\r\nSet the proxy in vue.config.js as\r\n\r\n```js\r\nmodule.exports = {\r\n  devServer: {\r\n    port: 4000,\r\n    proxy: {\r\n      \"/api\": {\r\n        target: \"http://localhost:5000/\"\r\n      },\r\n      \"/users\": {\r\n        target: \"http://localhost:5000/\"\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nNow all the requests to localhost:4000/user and /api should be proxied to the localhost:5000\r\n\r\n### What is expected?\r\nBy default [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware#options) configures the proxy with `changeOrigin: false`, so a request should be proxied without changing the origin. The response should be:\r\n\r\n```\r\ncurl -I http://localhost:4000/users/login\r\nHTTP/1.1 301 MOVED PERMANENTLY\r\nX-Powered-By: Express\r\nserver: gunicorn/19.8.1\r\ndate: Sun, 15 Jul 2018 05:11:22 GMT\r\nconnection: close\r\ncontent-type: text/html; charset=utf-8\r\ncontent-length: 275\r\nlocation: http://localhost:4000/users/login/\r\n```\r\n\r\n### What is actually happening?\r\n```\r\ncurl -I http://localhost:4000/users/login\r\nHTTP/1.1 301 MOVED PERMANENTLY\r\nX-Powered-By: Express\r\nserver: gunicorn/19.8.1\r\ndate: Sun, 15 Jul 2018 05:09:52 GMT\r\nconnection: close\r\ncontent-type: text/html; charset=utf-8\r\ncontent-length: 275\r\nlocation: http://localhost:5000/users/login/\r\n```\r\nNotice the  port 5000 in the response.\r\n\r\n---\r\nWhen I update the config to read\r\n\r\n```js\r\nmodule.exports = {\r\n  devServer: {\r\n    port: 4000,\r\n    proxy: {\r\n      \"/api\": {\r\n        target: \"http://localhost:5000/\"\r\n      },\r\n      \"/users\": {\r\n        target: \"http://localhost:5000/\",\r\n        changeOrigin: false\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nI get the expected response without change of the Origin. By default the changeOrigin flag is supposed to be off, but I have to set it off explicitly when using `vue-cli-service serve`.\r\n\r\n<!-- generated by vue-issues. DO NOT REMOVE -->"},"comment":{"url":"https://api.github.com/repos/vuejs/vue-cli/issues/comments/405097865","html_url":"https://github.com/vuejs/vue-cli/issues/1856#issuecomment-405097865","issue_url":"https://api.github.com/repos/vuejs/vue-cli/issues/1856","id":405097865,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNTA5Nzg2NQ==","user":{"login":"LinusBorg","id":1444526,"node_id":"MDQ6VXNlcjE0NDQ1MjY=","avatar_url":"https://avatars3.githubusercontent.com/u/1444526?v=4","gravatar_id":"","url":"https://api.github.com/users/LinusBorg","html_url":"https://github.com/LinusBorg","followers_url":"https://api.github.com/users/LinusBorg/followers","following_url":"https://api.github.com/users/LinusBorg/following{/other_user}","gists_url":"https://api.github.com/users/LinusBorg/gists{/gist_id}","starred_url":"https://api.github.com/users/LinusBorg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LinusBorg/subscriptions","organizations_url":"https://api.github.com/users/LinusBorg/orgs","repos_url":"https://api.github.com/users/LinusBorg/repos","events_url":"https://api.github.com/users/LinusBorg/events{/privacy}","received_events_url":"https://api.github.com/users/LinusBorg/received_events","type":"User","site_admin":false},"created_at":"2018-07-15T15:04:00Z","updated_at":"2018-07-15T15:04:00Z","author_association":"MEMBER","body":"@akryum Hie isssue is that we set `changeOrigin: true` as a default for all proxy settings, while the default for the webpack-dev-server implementation (and the underlying proxy lib it's using) is `false`.\r\n\r\n@tecoholic we chose this default because our experience from the previous cli version was that people very, very often have problems with CORS when using the proxy option, and `changeOrigin: true` solves most of those. \r\n\r\nWe could document this better I think "}}
{"actor":{"display_login":"LinusBorg"}}