PLT-3408 Add SiteURL to config.json (#3692)

* PLT-3408 Changed serverside code to get the service's URL from config.json

* PLT-3408 Changed most clientside code to use the SiteURL config setting instead of window.location

* PLT-3408 Changed default SiteURL to be autodetected
Этот коммит содержится в:
Harrison Healey
2016-08-02 16:37:09 -04:00
коммит произвёл GitHub
родитель e67bbcb0ae
Коммит c4a3118e9f
26 изменённых файлов: 89 добавлений и 117 удалений

Просмотреть файл

@@ -32,12 +32,26 @@ const MAX_WEBSOCKET_FAILS = 7;
export function initialize() {
if (window.WebSocket) {
let protocol = 'ws://';
if (window.location.protocol === 'https:') {
protocol = 'wss://';
let connUrl = window.mm_config.SiteURL;
// replace the protocol with a websocket one
if (connUrl.startsWith('https:')) {
connUrl = connUrl.replace(/^https:/, 'wss:');
} else {
connUrl = connUrl.replace(/^http:/, 'ws:');
}
const connUrl = protocol + location.host + ((/:\d+/).test(location.host) ? '' : Utils.getWebsocketPort(protocol)) + Client.getUsersRoute() + '/websocket';
// append a port number if one isn't already specified
if (!(/:\d+$/).test(connUrl)) {
if (connUrl.startsWith('wss:')) {
connUrl += ':' + global.window.mm_config.WebsocketSecurePort;
} else {
connUrl += ':' + global.window.mm_config.WebsocketPort;
}
}
// append the websocket api path
connUrl += Client.getUsersRoute() + '/websocket';
WebSocketClient.setEventCallback(handleEvent);
WebSocketClient.setReconnectCallback(handleReconnect);

Просмотреть файл

@@ -4,6 +4,7 @@
import ReactDOM from 'react-dom';
import Constants from 'utils/constants.jsx';
import {Modal, Tooltip, OverlayTrigger} from 'react-bootstrap';
import TeamStore from 'stores/team_store.jsx';
import * as Utils from 'utils/utils.jsx';
import {FormattedMessage} from 'react-intl';
@@ -130,8 +131,8 @@ export default class ChangeUrlModal extends React.Component {
serverError = <div className='form-group has-error'><p className='input__help error'>{this.props.serverError}</p></div>;
}
const fullTeamUrl = Utils.getTeamURLFromAddressBar();
const teamURL = Utils.getShortenedTeamURL();
const fullTeamUrl = TeamStore.getCurrentTeamUrl();
const teamURL = Utils.getShortenedTeamURL(TeamStore.getCurrentTeamUrl());
const urlTooltip = (
<Tooltip id='urlTooltip'>{fullTeamUrl}</Tooltip>
);

Просмотреть файл

@@ -123,7 +123,7 @@ export default class ChannelHeader extends React.Component {
});
const townsquare = ChannelStore.getByName('town-square');
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + townsquare.name);
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + townsquare.name);
},
(err) => {
AsyncClient.dispatchError(err, 'handleLeave');

Просмотреть файл

@@ -5,6 +5,7 @@ import * as Utils from 'utils/utils.jsx';
import {FormattedMessage} from 'react-intl';
import {Modal} from 'react-bootstrap';
import TeamStore from 'stores/team_store.jsx';
import * as TextFormatting from 'utils/text_formatting.jsx';
import React from 'react';
@@ -44,7 +45,7 @@ export default class ChannelInfoModal extends React.Component {
channelIcon = (<span className='fa fa-lock'/>);
}
const channelURL = Utils.getTeamURLFromAddressBar() + '/channels/' + channel.name;
const channelURL = TeamStore.getCurrentTeamUrl() + '/channels/' + channel.name;
let channelPurpose = null;
if (channel.purpose) {

Просмотреть файл

@@ -105,7 +105,7 @@ export default class TeamUrl extends React.Component {
nameDivClass += ' has-error';
}
const title = `${Utils.getWindowLocationOrigin()}/`;
const title = `${window.mm_config.SiteURL}/`;
const urlTooltip = (
<Tooltip id='urlTooltip'>{title}</Tooltip>
);

Просмотреть файл

@@ -102,7 +102,7 @@ class FileAttachment extends React.Component {
getFileInfoFromName(name) {
var fileInfo = utils.splitFileLocation(name);
fileInfo.path = utils.getWindowLocationOrigin() + Client.getFilesRoute() + '/get' + fileInfo.path;
fileInfo.path = Client.getFilesRoute() + '/get' + fileInfo.path;
return fileInfo;
}

Просмотреть файл

@@ -97,7 +97,7 @@ export default class InstalledIncomingWebhook extends React.Component {
id='installed_integrations.url'
defaultMessage='URL: {url}'
values={{
url: Utils.getWindowLocationOrigin() + '/hooks/' + incomingWebhook.id
url: window.mm_config.SiteURL + '/hooks/' + incomingWebhook.id
}}
/>
</span>

Просмотреть файл

@@ -277,7 +277,7 @@ export default class LoginController extends React.Component {
}
createLoginOptions() {
const extraParam = Utils.getUrlParameter('extra');
const extraParam = this.props.location.query.extra;
let extraBox = '';
if (extraParam) {
if (extraParam === Constants.SIGNIN_CHANGE) {

Просмотреть файл

@@ -74,7 +74,7 @@ export default class MoreChannels extends React.Component {
channel,
() => {
$(ReactDOM.findDOMNode(this.refs.modal)).modal('hide');
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name);
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + channel.name);
this.setState({joiningChannel: ''});
},
(err) => {

Просмотреть файл

@@ -87,7 +87,7 @@ export default class MoreDirectChannels extends React.Component {
Utils.openDirectChannelToUser(
teammate,
(channel) => {
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name);
browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/' + channel.name);
this.setState({loadingDMChannel: -1});
this.handleHide();
},

Просмотреть файл

@@ -88,7 +88,7 @@ export default class NavbarDropdown extends React.Component {
return (
<li>
<Link to={'/' + Utils.getTeamNameFromUrl() + '/emoji'}>
<Link to={'/' + this.props.teamName + '/emoji'}>
<FormattedMessage
id='navbar_dropdown.emoji'
defaultMessage='Custom Emoji'
@@ -207,7 +207,7 @@ export default class NavbarDropdown extends React.Component {
if (integrationsEnabled && (isAdmin || window.mm_config.EnableOnlyAdminIntegrations !== 'true')) {
integrationsLink = (
<li>
<Link to={'/' + Utils.getTeamNameFromUrl() + '/integrations'}>
<Link to={'/' + this.props.teamName + '/integrations'}>
<FormattedMessage
id='navbar_dropdown.integrations'
defaultMessage='Integrations'

Просмотреть файл

@@ -73,7 +73,7 @@ export default class NeedsTeam extends React.Component {
// Go to tutorial if we are first arriving
const tutorialStep = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, UserStore.getCurrentId(), 999);
if (tutorialStep <= TutorialSteps.INTRO_SCREENS) {
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/tutorial');
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/tutorial');
}
}

Просмотреть файл

@@ -3,6 +3,7 @@
import * as Utils from 'utils/utils.jsx';
import Client from 'client/web_client.jsx';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import NewChannelModal from './new_channel_modal.jsx';
@@ -117,7 +118,7 @@ class NewChannelFlow extends React.Component {
});
this.props.onModalDismissed();
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + data2.channel.name);
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + data2.channel.name);
}
);
},

Просмотреть файл

@@ -3,6 +3,7 @@
import $ from 'jquery';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import {Popover, Overlay} from 'react-bootstrap';
import * as Utils from 'utils/utils.jsx';
@@ -36,7 +37,7 @@ export default class PopoverListMembers extends React.Component {
Utils.openDirectChannelToUser(
teammate,
(channel, channelAlreadyExisted) => {
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name);
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + channel.name);
if (channelAlreadyExisted) {
this.closePopover();
}

Просмотреть файл

@@ -4,10 +4,10 @@
import $ from 'jquery';
import ReactDOM from 'react-dom';
import ChannelStore from 'stores/channel_store.jsx';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import BrowserStore from 'stores/browser_store.jsx';
import * as Utils from 'utils/utils.jsx';
import {FormattedMessage} from 'react-intl';
import {browserHistory} from 'react-router/es6';
@@ -36,7 +36,7 @@ export default class RemovedFromChannelModal extends React.Component {
var townSquare = ChannelStore.getByName('town-square');
setTimeout(
() => {
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + townSquare.name);
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + townSquare.name);
},
1);

Просмотреть файл

@@ -4,6 +4,7 @@
import $ from 'jquery';
import UserProfile from './user_profile.jsx';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import * as GlobalActions from 'actions/global_actions.jsx';
@@ -151,7 +152,7 @@ export default class SearchResultsItem extends React.Component {
this.hideSidebar();
}
this.shrinkSidebar();
browserHistory.push('/' + window.location.pathname.split('/')[1] + '/pl/' + post.id);
browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/pl/' + post.id);
}
}
className='search-item__jump'

Просмотреть файл

@@ -12,7 +12,6 @@ import Constants from 'utils/constants.jsx';
const ActionTypes = Constants.ActionTypes;
import * as AsyncClient from 'utils/async_client.jsx';
import Client from 'client/web_client.jsx';
import * as Utils from 'utils/utils.jsx';
import ChannelStore from 'stores/channel_store.jsx';
import emojiRoute from 'routes/route_emoji.jsx';
@@ -57,7 +56,7 @@ function doChannelChange(state, replace, callback) {
function preNeedsTeam(nextState, replace, callback) {
// First check to make sure you're in the current team
// for the current url.
var teamName = Utils.getTeamNameFromUrl();
const teamName = nextState.params.team;
var team = TeamStore.getByName(teamName);
const oldTeamId = TeamStore.getCurrentId();

Просмотреть файл

@@ -11,12 +11,6 @@ const ActionTypes = Constants.ActionTypes;
const CHANGE_EVENT = 'change';
var Utils;
function getWindowLocationOrigin() {
if (!Utils) {
Utils = require('utils/utils.jsx'); //eslint-disable-line global-require
}
return Utils.getWindowLocationOrigin();
}
class TeamStoreClass extends EventEmitter {
constructor() {
@@ -87,23 +81,23 @@ class TeamStoreClass extends EventEmitter {
getCurrentTeamUrl() {
if (this.getCurrent()) {
return getWindowLocationOrigin() + '/' + this.getCurrent().name;
return window.mm_config.SiteURL + '/' + this.getCurrent().name;
}
return null;
return '';
}
getCurrentTeamRelativeUrl() {
if (this.getCurrent()) {
return '/' + this.getCurrent().name;
}
return null;
return '';
}
getCurrentInviteLink() {
const current = this.getCurrent();
if (current) {
return getWindowLocationOrigin() + '/signup_user_complete/?id=' + current.invite_id;
return window.mm_config.SiteURL + '/signup_user_complete/?id=' + current.invite_id;
}
return '';
@@ -112,10 +106,10 @@ class TeamStoreClass extends EventEmitter {
getTeamUrl(id) {
const team = this.get(id);
if (team) {
return getWindowLocationOrigin() + '/' + team.name;
return window.mm_config.SiteURL + '/' + team.name;
}
return null;
return '';
}
saveTeam(team) {

Просмотреть файл

@@ -99,20 +99,6 @@ export function isSystemAdmin(roles) {
return false;
}
export function getDomainWithOutSub() {
var parts = window.location.host.split('.');
if (parts.length === 1) {
if (parts[0].indexOf('dockerhost') > -1) {
return 'dockerhost:8065';
}
return 'localhost:8065';
}
return parts[1] + '.' + parts[2];
}
export function getCookie(name) {
var value = '; ' + document.cookie;
var parts = value.split('; ' + name + '=');
@@ -171,18 +157,6 @@ export function ding() {
}
}
export function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1];
}
}
return null;
}
export function getDateForUnixTicks(ticks) {
return new Date(ticks);
}
@@ -1015,18 +989,6 @@ export function displayUsernameForUser(user) {
return username;
}
//IE10 does not set window.location.origin automatically so this must be called instead when using it
export function getWindowLocationOrigin() {
var windowLocationOrigin = window.location.origin;
if (!windowLocationOrigin) {
windowLocationOrigin = window.location.protocol + '//' + window.location.hostname;
if (window.location.port) {
windowLocationOrigin += ':' + window.location.port;
}
}
return windowLocationOrigin;
}
// Converts a file size in bytes into a human-readable string of the form '123MB'.
export function fileSizeToString(bytes) {
// it's unlikely that we'll have files bigger than this
@@ -1045,7 +1007,7 @@ export function fileSizeToString(bytes) {
// Converts a filename (like those attached to Post objects) to a url that can be used to retrieve attachments from the server.
export function getFileUrl(filename) {
return getWindowLocationOrigin() + Client.getFilesRoute() + '/get' + filename;
return Client.getFilesRoute() + '/get' + filename;
}
// Gets the name of a file (including extension) from a given url or file path.
@@ -1151,20 +1113,7 @@ export function importSlack(file, success, error) {
Client.importSlack(formData, success, error);
}
export function getTeamURLFromAddressBar() {
return window.location.origin + '/' + window.location.pathname.split('/')[1];
}
export function getTeamNameFromUrl() {
return window.location.pathname.split('/')[1];
}
export function getTeamURLNoOriginFromAddressBar() {
return '/' + window.location.pathname.split('/')[1];
}
export function getShortenedTeamURL() {
const teamURL = getTeamURLFromAddressBar();
export function getShortenedTeamURL(teamURL = '') {
if (teamURL.length > 35) {
return teamURL.substring(0, 10) + '...' + teamURL.substring(teamURL.length - 12, teamURL.length) + '/';
}