Fix localhost

Handle automatic subdomain redirect
This commit is contained in:
Tom Moor 2018-11-03 22:40:33 -07:00
parent 6418712c47
commit 1be8e13828
6 changed files with 26 additions and 27 deletions

View File

@ -24,6 +24,14 @@ const Auth = observer(({ auth, children }: Props) => {
return <LoadingIndicator />;
}
if (
team.subdomain &&
!window.location.hostname.startsWith(team.subdomain)
) {
window.location.href = `${team.url}${window.location.pathname}`;
return <LoadingIndicator />;
}
// Only initialize stores once. Kept in global scope because otherwise they
// will get overridden on route change
if (!authenticatedStores) {

View File

@ -32,7 +32,7 @@ const RealButton = styled.button`
}
&:disabled {
opacity: 0.8;
opacity: 0.6;
cursor: default;
}

View File

@ -84,18 +84,10 @@ class Details extends React.Component<Props> {
<CenteredContent>
<PageTitle title="Details" />
<h1>Details</h1>
{team.slackConnected && (
<HelpText>
This team is connected to a <strong>Slack</strong> team. Your
colleagues can join by signing in with their Slack account details.
</HelpText>
)}
{team.googleConnected && (
<HelpText>
This team is connected to a <strong>Google</strong> domain. Your
colleagues can join by signing in with their Google account.
</HelpText>
)}
<HelpText>
These details affect the way that your Outline appears to everyone on
the team.
</HelpText>
<ProfilePicture column>
<LabelText>Logo</LabelText>
@ -129,13 +121,14 @@ class Details extends React.Component<Props> {
name="subdomain"
value={this.subdomain || ''}
onChange={this.handleSubdomainChange}
placeholder="Optional"
autocomplete={false}
autocomplete="off"
minLength={4}
maxLength={32}
short
/>
{this.subdomain && (
<HelpText small>
You will access your knowledgebase at{' '}
Your knowledgebase will be accessed at{' '}
<strong>{this.subdomain}.getoutline.com</strong>
</HelpText>
)}

View File

@ -1,5 +1,5 @@
// @flow
import _ from 'lodash';
import { map } from 'lodash';
import invariant from 'invariant';
import stores from 'stores';
@ -51,7 +51,7 @@ class ApiClient {
body,
headers,
redirect: 'follow',
credentials: 'include',
credentials: 'omit',
});
if (response.status >= 200 && response.status < 300) {
@ -89,7 +89,7 @@ class ApiClient {
// Helpers
constructQueryString = (data: Object) => {
return _.map(data, (v, k) => {
return map(data, (v, k) => {
return `${encodeURIComponent(k)}=${encodeURIComponent(v)}`;
}).join('&');
};

View File

@ -1,6 +1,6 @@
// @flow
import uuid from 'uuid';
import url from 'url';
import { URL } from 'url';
import { DataTypes, sequelize, Op } from '../sequelize';
import { publicS3Endpoint, uploadToS3FromUrl } from '../utils/s3';
import { RESERVED_SUBDOMAINS } from '../utils/domains';
@ -47,11 +47,9 @@ const Team = sequelize.define(
url() {
if (!this.subdomain) return process.env.URL;
const u = url.parse(process.env.URL);
if (u.hostname) {
u.hostname = `${this.subdomain}.${u.hostname}`;
return u.href;
}
const url = new URL(process.env.URL);
url.host = `${this.subdomain}.${url.host}`;
return url.href.replace(/\/$/, '');
},
},
}

View File

@ -67,8 +67,8 @@ router.get('/changelog', async ctx => {
router.get('/', async ctx => {
const lastSignedIn = ctx.cookies.get('lastSignedIn');
const accessToken = ctx.cookies.get('accessToken');
const subdomain = parseDomain(ctx.request.hostname).subdomain;
console.log('subdomain', subdomain);
const domain = parseDomain(ctx.request.hostname);
const subdomain = domain ? domain.subdomain : false;
if (accessToken) {
return renderapp(ctx);