Rober Rober - 5 months ago 96
reST (reStructuredText) Question

Angular 1.0.7: Https api call in $resource

I have an Angular1.0.7 webapp that is making calls to an rails API listening in an specific port. We want to migrate to HTTPS protocol for security reasons. Is it possible to "autodetect" the protocol in the resource api call?

Example resource call:

function($resource, SERVER_URL){
var languages =
$resource('http://' + SERVER_URL +'/:action/:id', {action:'languages', id: '@id'}, {...

I have read somewhere you can just call like this, to autodetect the protocol:

$resource('/:action/:id', {action:'languages', id: '@id'}

However, my api listes in an specific port, so I need to tell it somehow.

Answer Source

You have to try scheme relative URL like:

$resource('//' + SERVER_URL +'/:action/:id', { ...

without http: at the beginning.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download