Skip to content

Commit

Permalink
Use relative url instead of static urls (#1078)
Browse files Browse the repository at this point in the history
* Use relative url instead of static urls
* Add helper functions to get API url and Server urls
* Fix documentation urls that were using _utils instead of relative
* Changed default configuration in settings.json
  • Loading branch information
popojargo committed Jun 27, 2018
1 parent 2b9824a commit 8a3e520
Show file tree
Hide file tree
Showing 26 changed files with 163 additions and 132 deletions.
3 changes: 2 additions & 1 deletion app/addons/activetasks/layout.js
Expand Up @@ -11,6 +11,7 @@
// the License.

import React from 'react';
import Helpers from "../../helpers";
import FauxtonAPI from "../../core/api";
import {OnePane, OnePaneHeader, OnePaneContent} from '../components/layouts';
import {ActiveTasksController, ActiveTasksPollingWidgetController} from "./components";
Expand All @@ -25,7 +26,7 @@ export const ActiveTasksLayout = () => {
<OnePaneHeader
crumbs={crumbs}
docURL={FauxtonAPI.constants.DOC_URLS.ACTIVE_TASKS}
endpoint={`${window.location.origin}/_active_tasks`}
endpoint={Helpers.getApiUrl('/_active_tasks')}
>
<ActiveTasksPollingWidgetController />
</OnePaneHeader>
Expand Down
4 changes: 2 additions & 2 deletions app/addons/activetasks/resources.js
Expand Up @@ -10,14 +10,14 @@
// License for the specific language governing permissions and limitations under
// the License.

import app from "../../app";
import Helpers from "../../helpers";
import Actions from "./actions";
var Active = {};

Active.AllTasks = Backbone.Collection.extend({

url: function () {
return app.host + '/_active_tasks';
return Helpers.getServerUrl('/_active_tasks');
},

pollingFetch: function () { //still need this for the polling
Expand Down
13 changes: 9 additions & 4 deletions app/addons/auth/api.js
Expand Up @@ -11,6 +11,7 @@
// the License.

import app from './../../app';
import Helpers from "../../helpers";
import { defaultsDeep } from "lodash";

export const json = (url, opts = {}) => fetch(
Expand Down Expand Up @@ -43,7 +44,8 @@ export const formEncoded = (url, opts = {}) => fetch(


export function createAdmin({name, password, node}) {
return json(`${app.host}/_node/${node}/_config/admins/${name}`, {
const url = Helpers.getServerUrl(`/_node/${node}/_config/admins/${name}`);
return json(url, {
method: "PUT",
body: JSON.stringify(password)
});
Expand All @@ -56,7 +58,8 @@ export function getSession() {
return loggedInSessionPromise;
}

const promise = json(app.host + "/_session").then(resp => {
const url = Helpers.getServerUrl('/_session');
const promise = json(url).then(resp => {
if (resp.userCtx.name) {
loggedInSessionPromise = promise;
}
Expand All @@ -67,15 +70,17 @@ export function getSession() {
}

export function login(body) {
return formEncoded(app.host + "/_session", {
const url = Helpers.getServerUrl('/_session');
return formEncoded(url, {
method: "POST",
body: app.utils.queryParams(body)
});
}

export function logout() {
loggedInSessionPromise = null;
return formEncoded(app.host + "/_session", {
const url = Helpers.getServerUrl('/_session');
return formEncoded(url, {
method: "DELETE",
body: app.utils.queryParams({ username: "_", password: "_" })
});
Expand Down
9 changes: 3 additions & 6 deletions app/addons/cluster/resources.js
Expand Up @@ -10,17 +10,14 @@
// License for the specific language governing permissions and limitations under
// the License.

import app from "../../app";
import FauxtonAPI from "../../core/api";
import Helpers from "../../helpers";

var Cluster = FauxtonAPI.addon();

Cluster.ClusterNodes = Backbone.Model.extend({
url: function (context) {
if (context === 'apiurl') {
return window.location.origin + '/_membership';
}
return app.host + '/_membership';
url: function () {
return Helpers.getServerUrl('/_membership');
},

parse: function (res) {
Expand Down
9 changes: 4 additions & 5 deletions app/addons/config/resources.js
Expand Up @@ -10,8 +10,8 @@
// License for the specific language governing permissions and limitations under
// the License.

import app from "../../app";
import FauxtonAPI from "../../core/api";
import Helpers from "../../helpers";
import { deleteRequest, put } from "../../core/ajax";

var Config = FauxtonAPI.addon();
Expand All @@ -23,9 +23,9 @@ Config.OptionModel = Backbone.Model.extend({
if (!this.get('node')) {
throw new Error('no node set');
}

return app.host + '/_node/' + this.get('node') + '/_config/' +
const endpointUrl = '/_node/' + this.get('node') + '/_config/' +
this.get('sectionName') + '/' + encodeURIComponent(this.get('optionName'));
return Helpers.getServerUrl(endpointUrl);
},

isNew () { return false; },
Expand Down Expand Up @@ -59,8 +59,7 @@ Config.ConfigModel = Backbone.Model.extend({
if (!this.get('node')) {
throw new Error('no node set');
}

return app.host + '/_node/' + this.get('node') + '/_config';
return Helpers.getServerUrl('/_node/' + this.get('node') + '/_config');
},

parse (resp) {
Expand Down
3 changes: 2 additions & 1 deletion app/addons/cors/reducers.js
Expand Up @@ -11,6 +11,7 @@
// the License.

import ActionTypes from "./actiontypes";
import _ from "lodash";

const initialState = {
corsEnabled: false,
Expand All @@ -34,7 +35,7 @@ export default function cors (state = initialState, action) {
isLoading: false,
node: corsOptions.node,
corsEnabled: corsOptions.corsEnabled,
isAllOrigins: _.include(corsOptions.origins, '*'),
isAllOrigins: _.includes(corsOptions.origins, '*'),
origins: corsOptions.origins,
deleteDomainModalVisible: false,
domainToDelete: ''
Expand Down
3 changes: 2 additions & 1 deletion app/addons/databases/actions.js
Expand Up @@ -10,6 +10,7 @@
// License for the specific language governing permissions and limitations under
// the License.
import app from "../../app";
import Helpers from "../../helpers";
import FauxtonAPI from "../../core/api";
import { get } from "../../core/ajax";
import Stores from "./stores";
Expand Down Expand Up @@ -184,7 +185,7 @@ export default {
limit: 30
});

const url = `${app.host}/_all_dbs${query}`;
const url = Helpers.getServerUrl(`/_all_dbs${query}`);
get(url).then((dbs) => {
const options = dbs.map(db => {
return {
Expand Down
19 changes: 11 additions & 8 deletions app/addons/databases/base.js
Expand Up @@ -11,6 +11,7 @@
// the License.

import app from "../../app";
import Helpers from "../../helpers";
import FauxtonAPI from "../../core/api";
import Databases from "./routes";
import "./assets/less/databases.less";
Expand All @@ -34,53 +35,55 @@ Databases.databaseUrl = function (database) {

FauxtonAPI.registerUrls('changes', {
server: function (id, query) {
return app.host + '/' + id + '/_changes' + query;
return Helpers.getServerUrl('/' + id + '/_changes' + query);
},

app: function (id, query) {
return '/database/' + id + '/_changes' + query;
},

apiurl: function (id, query) {
return window.location.origin + '/' + id + '/_changes' + query;
return Helpers.getApiUrl('/' + id + '/_changes' + query);
}
});

FauxtonAPI.registerUrls('allDBs', {
server: function (query = '') {
return `${app.host}/_all_dbs${query}`;
return Helpers.getServerUrl(`/_all_dbs${query}`);
},

app: function () {
return '_all_dbs';
},

apiurl: function () {
return window.location.origin + '/_all_dbs';
return Helpers.getApiUrl('/_all_dbs');
}
});

FauxtonAPI.registerUrls('databaseBaseURL', {
server: function (database) {
return window.location.origin + '/' + app.utils.safeURLName(database);
return Helpers.getServerUrl('/' + app.utils.safeURLName(database));
},
apiurl: function(database) {
return Helpers.getApiUrl('/' + app.utils.safeURLName(database));
},

app: function (database) {
return '/database/' + database;
}
});

FauxtonAPI.registerUrls('permissions', {
server: function (db) {
return app.host + '/' + db + '/_security';
return Helpers.getServerUrl('/' + db + '/_security');
},

app: function (db) {
return '/database/' + db + '/permissions';
},

apiurl: function (db) {
return window.location.origin + '/' + db + '/_security';
return Helpers.getApiUrl('/' + db + '/_security');
}
});

Expand Down
5 changes: 3 additions & 2 deletions app/addons/databases/resources.js
Expand Up @@ -11,6 +11,7 @@
// the License.

import app from "../../app";
import Helpers from "../../helpers";
import FauxtonAPI from "../../core/api";
import Documents from "../documents/resources";
var Databases = FauxtonAPI.addon();
Expand Down Expand Up @@ -47,15 +48,15 @@ Databases.Model = FauxtonAPI.Model.extend({
} else if (context === "web-index") {
return "#/database/" + this.safeID() + "/_all_docs?limit=" + Databases.DocLimit;
} else if (context === "apiurl") {
return window.location.origin + "/database/" + this.safeID() + "/_all_docs";
return Helpers.getApiUrl("/database/" + this.safeID() + "/_all_docs");
} else if (context === "changes") {
return FauxtonAPI.urls('changes', 'app', this.safeID(), '?descending=true&limit=100&include_docs=true');
} else if (context === "changes-apiurl") {
return FauxtonAPI.urls('changes', 'apiurl', this.safeID(), '?descending=true&limit=100&include_docs=true');
} else if (context === "app") {
return "/database/" + this.safeID();
}
return app.host + "/" + this.safeID();
return Helpers.getServerUrl("/" + this.safeID());

},

Expand Down
3 changes: 2 additions & 1 deletion app/addons/documentation/components.js
Expand Up @@ -11,6 +11,7 @@
// the License.

import React from "react";
import Helpers from '../../helpers';

const docLinks = [
{
Expand All @@ -20,7 +21,7 @@ const docLinks = [
},
{
title: 'CouchDB Official Documentation — Offline',
link: '/_utils/docs/index.html',
link: Helpers.getServerUrl('/docs/index.html'),
iconClassName: 'couchdb-icon'
},
{
Expand Down
4 changes: 2 additions & 2 deletions app/addons/documentation/tests/nightwatch/checksDocsPage.js
Expand Up @@ -14,13 +14,13 @@

module.exports = {
'Check the documentation page exists': function (client) {
var waitTime = client.globals.maxWaitTime;
const waitTime = client.globals.maxWaitTime;

client
.loginToGUI()
.clickWhenVisible('a[href="#/documentation"]')
.waitForElementVisible('a[href="http://docs.couchdb.org/en/latest/"]', waitTime, false)
.waitForElementVisible('a[href="/_utils/docs/index.html"]', waitTime, false)
.waitForElementVisible('a[href="./docs/index.html"]', waitTime, false)
.waitForElementVisible('a[href="http://blog.couchdb.org/"]', waitTime, false)
.waitForElementVisible('a[href="https://couchdb.apache.org/"]', waitTime, false)
.waitForElementVisible('a[href="https://github.com/apache/couchdb"]', waitTime, false)
Expand Down

0 comments on commit 8a3e520

Please sign in to comment.