-
Notifications
You must be signed in to change notification settings - Fork 12k
ng serve: support for proxy urls #889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
try this is from ember-cli and it worked in some previous version |
We haven't done such functionality no. If you find it working within |
Using To get it working in Firefox (38), I had to explicitly set the e.g.:
You could ofcourse also set it to the explicit content type you would be expecting e.g. 'application/json'. Also, you can set the
|
@fatsu @filipesilva Is it possible to save the proxy url somewhere in the angular-cli.json so it is always considered when I just do ng serve ? |
@filipesilva @dmnk89 seems I did not read what you wrote about the ember-cli file. So I tried to put this in the ember-cli file:
That works fine! Of courseits confusing at first time why use ember inside angular... but well it works! |
@bastienJS Angular CLI is based on Ember CLI. But, how to configure multi proxies? eg. /api for http://api.example.com |
@bastienJS I'm glad you found a way to persist it! It's counter-intuitive but at least it works for now. |
I'd like to mention that with #1455, the native ember-cli support for proxies probably doesn't work anymore. |
@filipesilva any idea/hack to get this working? I have full backend API available, I am developing an alternate client using ng2. So proxy option is very helpful to me for quick demo and testing. |
@TheLarkInn is there any simple way to have this with the webpack dev server? |
Webpack dev server configuration includes support for proxy. https://webpack.github.io/docs/webpack-dev-server.html#proxy We already have a dev server configuration object used here that we would need to simply tie the commandsOptions and apply to that config. Proxy setup was a little out of my wheelhouse so we left it open for those interested to PR or tackle after we cut a release. @mmrath hopefully this would give you a starting point if you wanted to submit a PR for it!! 👏 |
@TheLarkInn, @filipesilva thanks. I'll give it a go today. I am thinking of adding an option --proxy-config with argument to file path relative to project. The file can contain all the options available to webpack dev server which will be passed as is by clicking. I think this will allow lot of flexibility for cases like multiple proxy, URL rewrite etc. Do you think this is an acceptable approach? |
It sounds awesome!! If we implement it is like to see tests to verify that proxies are working (however it's done). Go ahead and make a PR and we can discuss the implementation from there. |
@mmrath while you are implementing This option does not work on ember-cli and I personally was not able to figure out , which options to use for node |
Someone tried solution I added above? |
@iamandrewluca now that cli moved to webpack, I am in favor of an webpack-y solution. |
@TheLarkInn when you have a moment, could you review PR#1487? |
Closed by #1487 |
Big thanks to @mmrath for adding this functionality! |
I have spent a lot of time searching how to make work the proxy settings, finally this worked for me: proxy.conf.json {
"/api/*": {
"target": "http://test.dev",
"changeOrigin": true,
"secure": false,
"logLevel": "debug"
}
} The important part is |
Hooray! |
I am running a hybrid app and am having problems with deep linking. I am moving to Angular-cli and now it seems bypass is not a supported option. |
doesn't angular2-webpack-starter achieve this with the webpack-dev-server option |
None of the above solutions but this worked for me: {
"/api": {
"target": "http://jsonplaceholder.typicode.com/",
"changeOrigin": true,
"secure": false,
"pathRewrite": {
"^/api": ""
},
"logLevel": "debug"
}
} |
For those looking, unable to get these proxy's to work, what did it for me was i forgot the http infront of localhost:8080 Working solution looks like this |
The proxy works great, but is there a way to put proxy configuration into
section to I also tried searching open issues but I wasn't able to find anything relevant. Should I file a feature request? |
I am not aware of any other way than described above.
and start it with |
I encountered the similar issues as @michaeljpeake, the proxy config does not work in my case. The backend is a nodejs application, served at port 3000. The frontend is NG 2 application generated by Angular CLI. I added a proxy.conf.json in the root of frontend application.
and changed the
When I run the application, I got error messages from cmd console.
The image should be accessed via http://localhost:4300/api/upload/uploads-1490782788752.png, but failed, and it is existed at http://localhost:3000/api/upload/uploads-1490782788752.png When I accessed http://localhost:4300/api/upload/uploads-1490782788752.png, in Chrome browser. It displays a message:
When access http://localhost:3000/api/upload/uploads-1490782788752.png, it displays the image directly. My local development environment:
|
var api = proxyMiddleware('/api', { the above code is in angular 1.x Help me to add headers to proxy as above from line number 05 to 08 |
None of the above solutions but this worked for me:
But there is a problem with this solution, when the proxy address changes, I need to change two places. Hope to have a better solution |
I have solved my own problem Now
http request is :
|
Please excuse my ignorance, as I am fairly new to angular. Does the proxy.config.json work when building and deploying to iis? |
It is just a development thing. No use for building or deployment
…On Tue, 16 May 2017, 5:18 PM MrBananaGuard ***@***.***> wrote:
Please excuse my ignorance, as I am fairly new to angular. Does the
proxy.config.json work when building and deploying to iis?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#889 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAHEN4voIdPt6nTtVFDHxgtkadCGAYsoks5r6U3hgaJpZM4IkTU3>
.
|
@mmrath Ok awesome, thanks. |
I've noticed that sometimes even with this proxy server set correctly, I got some erros. What I've realized that the issue was on my request (usually with PUT and POST). I passed a bad request at some point, then I got a reverse |
@guehmann @filipesilva just a suggestion, This configuration is pretty standard for webpack-dev-server and can be added to proxy docs for windows auth.
|
@ankeshdave But i didn't get it to work. I put your code in a file name proxy.conf.js and substitute the following with my values: "/api" -> "/v1.2" and my WebApi-method is reachable under http://localhost/Anytime.WebServices/v1.2/base/department/many then i run: ng serve --proxy-config proxy.conf.js the error is still the same, i changed localhost to the ip address and also the hostname, nothing happend. error is: zone.js:2263 GET http://localhost/Anytime.WebServices/v1.2/base/department/many 401 (Unauthorized) But CORS is fully enabled on any address, port and header on my WebApi. Perhaps you see my error. |
@guehmann there is something not configured with your CORS configuration you first need to get that working, I am also using CORS (tomcat as server) and windows authentication from LDAP, this configuration works, Also try putting
in place of
|
@ankeshdave Thank for your reply. So I'll check what is wrong with my WebApi. I tried your issue with changing to /Anytime... but the result was the same. My WebApi is an asp.net core configured cors as follows. // CORS kofigurieren and then I'll try to fix it an give response. Thank you very much. |
@ankeshdave Hi, I solved it with turning on anonymous authentication on the iis application. Now i can run the same WebApi with 'serve' and 'build' without any errors. Not even i need the proxy option. Thanks. |
suppose your proxy file is proxy.conf.json after you have to edit package.json file and add "start": "ng serve --proxy-config proxy.conf.json" in first braces where your project name, version available, so your new code looks like { main part start here, you have to start your application like npm start. and even you want to change the port then just add "start": "ng serve --port 5000 --proxy-config proxy.conf.json" |
@Dev-Pawar this only works for me if I use HashLocation strategy, does not work with PathLocation. Any ideas? |
I think you have used ** RouterModule.forRoot(routes, {useHash: true}) ** , jusr try it by removing {useHash: true}, as by default angular support PathLocationStrategy. so you can use like RouterModule.forRoot(routes) try this. hope it will work. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
At development time our teem needs to proxy AJAX-requests with urls that match certain patterns/regexes to a different machine running the application backend.
Is this use-case already covered but not yet documented by
ng serve
?If not I would like to propose this as a feature:
ng serve
If this however is not in the scope of
ng serve
, what benefits would our team lose if we were NOT usingng serve
in the dev-workflow at all?The text was updated successfully, but these errors were encountered: