diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/common/signin.ts | 2 | ||||
| -rw-r--r-- | src/config.ts | 11 | ||||
| -rw-r--r-- | src/server.ts | 13 | ||||
| -rw-r--r-- | src/web/app/common/mios.ts | 4 | ||||
| -rw-r--r-- | src/web/app/config.ts | 2 | ||||
| -rw-r--r-- | src/web/app/init.ts | 6 |
6 files changed, 20 insertions, 18 deletions
diff --git a/src/api/common/signin.ts b/src/api/common/signin.ts index c069fa4ec8..04c2cdac81 100644 --- a/src/api/common/signin.ts +++ b/src/api/common/signin.ts @@ -4,7 +4,7 @@ export default function(res, user, redirect: boolean) { const expires = 1000 * 60 * 60 * 24 * 365; // One Year res.cookie('i', user.account.token, { path: '/', - domain: `.${config.host}`, + domain: `.${config.hostname}`, secure: config.url.substr(0, 5) === 'https', httpOnly: false, expires: new Date(Date.now() + expires), diff --git a/src/config.ts b/src/config.ts index 09e06f3311..42dfd5f541 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,6 +3,7 @@ */ import * as fs from 'fs'; +import { URL } from 'url'; import * as yaml from 'js-yaml'; import isUrl = require('is-url'); @@ -102,9 +103,11 @@ type Source = { */ type Mixin = { host: string; + hostname: string; scheme: string; ws_scheme: string; secondary_host: string; + secondary_hostname: string; secondary_scheme: string; api_url: string; ws_url: string; @@ -128,14 +131,18 @@ export default function load() { if (!isUrl(config.url)) urlError(config.url); if (!isUrl(config.secondary_url)) urlError(config.secondary_url); + const url = new URL(config.url); + const secondaryUrl = new URL(config.secondary_url); config.url = normalizeUrl(config.url); config.secondary_url = normalizeUrl(config.secondary_url); - mixin.host = config.url.substr(config.url.indexOf('://') + 3); - mixin.scheme = config.url.substr(0, config.url.indexOf('://')); + mixin.host = url.host; + mixin.hostname = url.hostname; + mixin.scheme = url.protocol.replace(/:$/, ''); mixin.ws_scheme = mixin.scheme.replace('http', 'ws'); mixin.ws_url = `${mixin.ws_scheme}://api.${mixin.host}`; mixin.secondary_host = config.secondary_url.substr(config.secondary_url.indexOf('://') + 3); + mixin.secondary_hostname = secondaryUrl.hostname; mixin.secondary_scheme = config.secondary_url.substr(0, config.secondary_url.indexOf('://')); mixin.api_url = `${mixin.scheme}://api.${mixin.host}`; mixin.auth_url = `${mixin.scheme}://auth.${mixin.host}`; diff --git a/src/server.ts b/src/server.ts index 84e8c41489..7f66c42073 100644 --- a/src/server.ts +++ b/src/server.ts @@ -14,11 +14,6 @@ import vhost = require('vhost'); import log from './log-request'; import config from './conf'; -function extractHostname(host) { - const index = host.indexOf(':'); - return index < 0 ? host : host.substr(0, index); -} - /** * Init app */ @@ -58,11 +53,9 @@ app.use((req, res, next) => { /** * Register modules */ -const hostname = extractHostname(config.host); -const secondaryHostname = extractHostname(config.secondary_host); -app.use(vhost(`api.${hostname}`, require('./api/server'))); -app.use(vhost(secondaryHostname, require('./himasaku/server'))); -app.use(vhost(`file.${secondaryHostname}`, require('./file/server'))); +app.use(vhost(`api.${config.hostname}`, require('./api/server'))); +app.use(vhost(config.secondary_hostname, require('./himasaku/server'))); +app.use(vhost(`file.${config.secondary_hostname}`, require('./file/server'))); app.use(require('./web/server')); /** diff --git a/src/web/app/common/mios.ts b/src/web/app/common/mios.ts index 1c950c3e79..2c6c9988e7 100644 --- a/src/web/app/common/mios.ts +++ b/src/web/app/common/mios.ts @@ -3,7 +3,7 @@ import { EventEmitter } from 'eventemitter3'; import * as merge from 'object-assign-deep'; import * as uuid from 'uuid'; -import { host, apiUrl, swPublickey, version, lang, googleMapsApiKey } from '../config'; +import { hostname, apiUrl, swPublickey, version, lang, googleMapsApiKey } from '../config'; import Progress from './scripts/loading'; import Connection from './scripts/streaming/stream'; import { HomeStreamManager } from './scripts/streaming/home'; @@ -220,7 +220,7 @@ export default class MiOS extends EventEmitter { public signout() { localStorage.removeItem('me'); - document.cookie = `i=; domain=.${host}; expires=Thu, 01 Jan 1970 00:00:01 GMT;`; + document.cookie = `i=; domain=.${hostname}; expires=Thu, 01 Jan 1970 00:00:01 GMT;`; location.href = '/'; } diff --git a/src/web/app/config.ts b/src/web/app/config.ts index 24158c3aed..32710dd9c4 100644 --- a/src/web/app/config.ts +++ b/src/web/app/config.ts @@ -1,4 +1,5 @@ declare const _HOST_: string; +declare const _HOSTNAME_: string; declare const _URL_: string; declare const _API_URL_: string; declare const _DOCS_URL_: string; @@ -16,6 +17,7 @@ declare const _LICENSE_: string; declare const _GOOGLE_MAPS_API_KEY_: string; export const host = _HOST_; +export const hostname = _HOSTNAME_; export const url = _URL_; export const apiUrl = _API_URL_; export const docsUrl = _DOCS_URL_; diff --git a/src/web/app/init.ts b/src/web/app/init.ts index 28adfd3b07..6cc7ae6ce6 100644 --- a/src/web/app/init.ts +++ b/src/web/app/init.ts @@ -14,7 +14,7 @@ import ElementLocaleJa from 'element-ui/lib/locale/lang/ja'; import App from './app.vue'; import checkForUpdate from './common/scripts/check-for-update'; import MiOS, { API } from './common/mios'; -import { version, host, lang } from './config'; +import { version, hostname, lang } from './config'; let elementLocale; switch (lang) { @@ -60,8 +60,8 @@ console.info( window.clearTimeout((window as any).mkBootTimer); delete (window as any).mkBootTimer; -if (host != 'localhost') { - document.domain = host; +if (hostname != 'localhost') { + document.domain = hostname; } //#region Set lang attr |