-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$resource strips port from url #1243
Comments
Is this a bug or... what? Seems redundant to #942 Or are you making a bug asking specifically what @JamesDunne proposed |
It's supposed to be a bug. It's the same as #942, but that issue was closed with "you need to use escaping". My point here was to illustrate that escaping isn't really a solution (every first time user of angular using a port number will hit it and $http doesn't understand the escaping so you can't use the same URL). @JamesDunne's proposal seems fine, but I wasn't advocating any particular solution. |
I've just run into this problem too. Additionally, it doesn't seem to work escaping the colon with a backslash (using 1.0.2) |
The backslash escaping does not work for me; I'm using v1.0.2. |
I'm having the same problem: escaping : doesn't work and I'm using 1.0.2 Do you have found any solution? Trying to access a url of this kind: http://subdomain.domain.com:9000/some/parameters |
A workaround would be to include a |
Hi, that is really confusing problem. To fix that I was using {port} parameter in all resource instances as others do but, code gets really messy. So, I decided to have a single URL address in the configuration and came up with another solution, so try to use this: $resource('http://localhost:XXXX\:XXXX/api/entities'); Test (in Coffeescript) describe "Resource port replacment test", ->
entity=null
beforeEach module("YourApp")
beforeEach inject(($resource, $httpBackend) ->
@entity = $resource 'http://localhost:56789\:56789/api/entities'
@httpBackend = $httpBackend
@httpBackend.expectGET('http://localhost:56789/api/entities').
respond(200, '1'))
afterEach ->
@httpBackend.verifyNoOutstandingExpectation()
@httpBackend.verifyNoOutstandingRequest()
it "checking the address", ->
@entity.query {}
@httpBackend.flush() It's another trick, but works fine for me. Hope you guys can fix it in the next release. Cheers |
There is a also a disparity between how $resource and $http handle this. For example, if you use a common config variable with the double port (
UPDATE: This was mentioned in the original ticket. Sorry for the repost, but it's a major pain for cross-domain and local development. |
Ran into this issue today, was able to solve with the following:
(Note: I'm sure that's not the best way to do it) It seems that a While I imagine regressions would make it infeasible to change at this point a much more acceptable token would be something like |
You can escape port number using double Docs were updated in c398d7d thnx to @jsyrjala ! |
I think you can provide a better solution. The behaviour is different from $http. This is a workaround and very ugly. You should check "protocol://server:port". Are you really thinking that someone could use :port as variable? There are a lot of people asking for this problem. Don't fix it now, but keep it open please. |
How about we disallow :identifiers that start with a digit? This is a pretty common restriction (see identifiers in JS itself, and most programming languages), so I don't think anyone will be caught by surprise. Real-world impact should also be minimal, I assume. |
👍
|
I'm going to 👍 this issue as this is still a pretty gnarly issue -- definitely bit a first time user like me. The reason I hit it is because I'm doing local development on a Chrome app, so it makes sense that my endpoint would be something like http://localhost:3000, no? Just seems bizarre that I should have to escape the port number. I like @mernen's solution. |
I'd like to 👍 @mernen's solution. This is a real pain in the ass and it requires some kludgey code to get |
Just another 👍 to say I've been hit by this moving between |
Unfortunately the work around isn't feasible if you share URLs between $resource and $http. We have a subdirectory for the production deployment, so the url needs to change to app.com/subdirectory. What we did to solve this is, instead of injecting a service to all factories that returns the full URL with the port for development, and the URL with the subdirectory for production, we are now just returning '/subdirectory' for production and an empty string for development, and the browser completes the URL path. It works great. |
As @bbonamin said, escaping the colon works for for |
I see that it might be a pain for people sharing the same URL across |
@mernen has the best solution: let's change $resource so that patterns in URLs can't start with digit. |
Currently URLs like http://example.com:8080/some/path do not work with $resource without tricks because port number :8080 is handled as path parameter. This commit changes $resource to ignore parameters that start with a digit. Fixes angular#1243.
@pkozlowski-opensource yes I am motivated! Will try to create a pull request shortly. |
I disagree with @mernen and @jsyrjala. I think we should keep the behavior of |
This is already being addressed in #2778 |
@petebacondarwin that is exactly what I mean! The question remaining is: will this pull request be honored? And if yes in which release? |
I am pretty confident that it will be merged. Need to get it reviewed. |
OK people, let's all vote for PR #2778! |
This can be closed. It has landed in b94ca12 |
As of which version does this work? angular-seed still has the old version, see https://github.com/angular/angular-seed/blob/master/app/lib/angular/angular-resource.js#L290 |
the seed app uses angular 1.0.7, an outdated release of the stable branch. This change was introduced in the unstable branch, at 1.2.0rc1. This is part of the unstable branch, which contains quite a few breaking changes. Since it's not a huge change you could apply the commit to the stable branch as a patch. (If you click on the commit, you can see the releases (tags) and branches that contain this change. And the top of the resource file you linked to contains the version number) |
Yeah, I saw that it was in 1.2.0rc1 on the commit page. Didn't realize seed was outdated; angularjs.org says latest stable is 1.0.8? Completely separately, since REST is so core to just about every Web API written in the last few years, why isn't ngResource part of the core angular.j/angular.min.js file? |
Seed is outdated because it uses 1.0.7. 1.2 RC2 is still unstable. |
1.0.8 is highest stable, right? I agree on module separation. My question was:
|
|
I can see that, but I think you can get 80% of use cases with a basic version and config opts.
But isn't ngRoute still part of angular.js? I don't need to include any other file to get it.
Huh! It wasn't listed as on the Google site, but it is if you manually change the URL to do angular-resource.js or angular-resource.min.js. Same for cdnjs. You can even search on cdnjs, but it is not listed. Very helpful, thank you. |
We are unable to use angular's REST support directly, our project fits in that use case. |
I am sure many do. But I think REST in its basic forms cover so many use cases, and angular-resource is 2.7KB minified, 1.4KB gzipped, I can see it being core. But I am just a fairly new user (to Angular anyways) expressing an opinion. :-) |
As discussed in https://groups.google.com/forum/?fromgroups#!topic/angular/18aO0bIlEm0%5B1-25%5D, if you include a port in the URL passed to $resource, it gets stripped since everything with a colon is substituted.
Escaping the colon works, but that makes it a pain to use the same URL with $http (which doesn't seem to understand the escaping).
In general you should be using relative URLs, but the use case for needing the full path is for cross origin requests.
The text was updated successfully, but these errors were encountered: