$resource module stripping port :8888 from url.

5,516 views
Skip to first unread message

ItsLeeOwen

unread,
Apr 6, 2012, 7:57:31 PM4/6/12
to ang...@googlegroups.com
$resource.get isn't working locally with MAMP, and I've noticed that the :8888 is not present in the request url.  Any ideas on how to prevent that from happening?  Thanks!

Vojta Jína

unread,
Apr 7, 2012, 3:40:35 AM4/7/12
to ang...@googlegroups.com
Did you try escaping the colon with backslash ?

V.

On Fri, Apr 6, 2012 at 4:57 PM, ItsLeeOwen <l...@coderebelbase.com> wrote:
$resource.get isn't working locally with MAMP, and I've noticed that the :8888 is not present in the request url.  Any ideas on how to prevent that from happening?  Thanks!

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/6f_7eUMuy3YJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

ma...@andretavares.com

unread,
May 8, 2012, 7:36:00 AM5/8/12
to ang...@googlegroups.com
Having the same problem here!

The problem is that $resource interprets ":" as variables. This way, when you write ":8888" you either do something like 

$resource("http://localhost:8080", {8080: ':8080'}); and it will build the URL as you expected or it will interpret that there isn't a value to fill ":8080" and, therefore, the URL built is missing it.

To avoid confusion, this is the same as $resource("http://localhost:port", {port: ':8080'});

But my question still stands, isn't there a way for AngularJS to simply ignore the ":" as a variable in the case of URLs?


On Saturday, 7 April 2012 08:40:35 UTC+1, Vojta Jína wrote:
Did you try escaping the colon with backslash ?

V.

On Fri, Apr 6, 2012 at 4:57 PM, ItsLeeOwen <l...@coderebelbase.com> wrote:
$resource.get isn't working locally with MAMP, and I've noticed that the :8888 is not present in the request url.  Any ideas on how to prevent that from happening?  Thanks!

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/6f_7eUMuy3YJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.

Vojta Jína

unread,
May 16, 2012, 7:05:54 PM5/16/12
to ang...@googlegroups.com
We might ignore the colon for port number.

In meantime, escape the colon with a backslash.

V.
>>> angular+u...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/angular?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/HtnQrzuWL4kJ.
>
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.

jos...@feth.com

unread,
Jun 2, 2012, 11:17:19 AM6/2/12
to ang...@googlegroups.com
Has this issue been fixed, yet? In 1.0 rc10 it seems to be still there...
>>> angular+unsubscribe@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/angular?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/HtnQrzuWL4kJ.
>
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+unsubscribe@googlegroups.com.

Tom

unread,
Aug 8, 2012, 2:12:31 PM8/8/12
to ang...@googlegroups.com
I created a bug for this:

https://github.com/angular/angular.js/issues/1243
>>> angular+u...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/angular?hl=en.
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/HtnQrzuWL4kJ.
>
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.

Andy Joslin

unread,
Aug 8, 2012, 2:14:42 PM8/8/12
to ang...@googlegroups.com
What about:

$resource("http://me.com:888', {
  '888': 888
});

Tom

unread,
Aug 8, 2012, 2:31:29 PM8/8/12
to ang...@googlegroups.com
Yes, that works (almost -- see the previous comments)

The correct syntax is actually:

$resource("http://me.com:888', {
  '888': ':888'
});

But that's a hack, not a solution.

Tom

alex.k...@gmail.com

unread,
Oct 11, 2012, 7:20:44 AM10/11/12
to ang...@googlegroups.com, tomthee...@gmail.com
Using {port} parameter everywhere is messy. So try to use this:

```javascript
$resource('http://localhost:XXXX\:XXXX/api/entities'); 
```

Test (in Coffeescript)
```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. Hopefully Angular team will fix it in the next release.

Cheers
Alex

ganaraj p r

unread,
Oct 11, 2012, 7:34:46 AM10/11/12
to ang...@googlegroups.com, tomthee...@gmail.com
Just so that you dont define a url everywhere, how about using something like :


app.constant("baseUrl","http://localhost:56789\:56789");

and in your controllers you could do

function Ctrl(baseUrl){
     $resource(baseUrl+'/api/entities'); 
}

So when you want to deploy your app to the server you just change your url in one place.. and you are good to go.


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.



--
Regards,
Ganaraj P R

chri...@googlemail.com

unread,
Oct 18, 2012, 6:13:03 AM10/18/12
to ang...@googlegroups.com, tomthee...@gmail.com
Hi Ganaraj,

Actually I'm doing my first steps with angularjs / js to create a web-app, which is using an existing jee business/backend ( REST api). I'm not sure where I have to set the "app.constant("baseUrl","http://localhost:56789\:56789");". Is "app" the value of the ng-app attribute, which is set in the html content?

Cheers!
Christian

ganaraj p r

unread,
Oct 18, 2012, 7:06:32 AM10/18/12
to ang...@googlegroups.com, tomthee...@gmail.com
I used app as the variable for your module.

If you go to your app.js file ( or whichever file you use to start you angular app.).. you should see a line something like 

var app = angular.module('myModule', []);

I was referring to this variable. You might have defined it as perhaps

var myApp = angular.module('myModule', []); or even something else

Now ... after this you could add the constant. 

app.constant("baseUrl","http://localhost:56789\:56789");

and everywhere else you could inject this constant!

function MyCtrl(baseUrl){

// do your stuff!

chri...@googlemail.com

unread,
Oct 18, 2012, 7:13:35 AM10/18/12
to ang...@googlegroups.com, tomthee...@gmail.com
Perfect, now I have understand it. Thank u.

Matthias Dailey

unread,
Nov 5, 2013, 5:54:27 PM11/5/13
to ang...@googlegroups.com, tomthee...@gmail.com
The patch was not applied until version 1.2, which is in rc stage and has breaking changes, so it may not be good to just upgrade.
Here is how you can patch angular-resource.js and host it yourself:

Download angular-resource.js and edit it like so. According to the patch, you must replace line 348 with this:
         if (!(new RegExp("^\\d+$").test(param)) && param && (new RegExp("(^|[^\\\\]):" + param + "(\\W|$)").test(url))) {
The change is highlighted in green.

And that's it. Just host the file on your own web server and you can enjoy the functionality just like it was never broken 8-)
Reply all
Reply to author
Forward
0 new messages