blob: fcb373c7e5b410ea1ac601a31058e6195f834711 [file] [log] [blame]
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 ONOS GUI -- Remote -- General Purpose Functions
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080019 */
20(function () {
21 'use strict';
22
Simon Hunt1e4a0012015-01-21 11:36:08 -080023 var uiContext = '/onos/ui/',
24 rsSuffix = uiContext + 'rs/',
25 wsSuffix = uiContext + 'ws/';
26
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080027 angular.module('onosRemote')
28 .factory('UrlFnService', ['$location', function ($loc) {
29
Simon Hunt1e4a0012015-01-21 11:36:08 -080030 function matchSecure(protocol) {
31 var p = $loc.protocol(),
32 secure = (p === 'https' || p === 'wss');
33 return secure ? protocol + 's' : protocol;
34 }
35
36 function urlBase(protocol) {
37 return matchSecure(protocol) + '://' +
38 $loc.host() + ':' + $loc.port();
39 }
40
41 function httpPrefix(suffix) {
42 return urlBase('http') + suffix;
43 }
44
45 function wsPrefix(suffix) {
46 return urlBase('ws') + suffix;
47 }
48
49 function rsUrl(path) {
50 return httpPrefix(rsSuffix) + path;
51 }
52
53 function wsUrl(path) {
54 return wsPrefix(wsSuffix) + path;
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080055 }
56
57 return {
Simon Hunt1e4a0012015-01-21 11:36:08 -080058 rsUrl: rsUrl,
59 wsUrl: wsUrl
Bri Prebilic Coleeb28b0b2015-01-15 14:20:58 -080060 };
61 }]);
62
63}());