forked from mirror/misskey
Merge pull request #1292 from akihikodaki/config
Define hostname and secondary_hostname in config
This commit is contained in:
commit
ca78cbc7eb
@ -103,9 +103,11 @@ type Source = {
|
|||||||
*/
|
*/
|
||||||
type Mixin = {
|
type Mixin = {
|
||||||
host: string;
|
host: string;
|
||||||
|
hostname: string;
|
||||||
scheme: string;
|
scheme: string;
|
||||||
ws_scheme: string;
|
ws_scheme: string;
|
||||||
secondary_host: string;
|
secondary_host: string;
|
||||||
|
secondary_hostname: string;
|
||||||
secondary_scheme: string;
|
secondary_scheme: string;
|
||||||
api_url: string;
|
api_url: string;
|
||||||
ws_url: string;
|
ws_url: string;
|
||||||
@ -130,14 +132,17 @@ export default function load() {
|
|||||||
if (!isUrl(config.secondary_url)) urlError(config.secondary_url);
|
if (!isUrl(config.secondary_url)) urlError(config.secondary_url);
|
||||||
|
|
||||||
const url = new URL(config.url);
|
const url = new URL(config.url);
|
||||||
|
const secondaryUrl = new URL(config.secondary_url);
|
||||||
config.url = normalizeUrl(config.url);
|
config.url = normalizeUrl(config.url);
|
||||||
config.secondary_url = normalizeUrl(config.secondary_url);
|
config.secondary_url = normalizeUrl(config.secondary_url);
|
||||||
|
|
||||||
mixin.host = url.host;
|
mixin.host = url.host;
|
||||||
|
mixin.hostname = url.hostname;
|
||||||
mixin.scheme = url.protocol.replace(/:$/, '');
|
mixin.scheme = url.protocol.replace(/:$/, '');
|
||||||
mixin.ws_scheme = mixin.scheme.replace('http', 'ws');
|
mixin.ws_scheme = mixin.scheme.replace('http', 'ws');
|
||||||
mixin.ws_url = `${mixin.ws_scheme}://api.${mixin.host}`;
|
mixin.ws_url = `${mixin.ws_scheme}://api.${mixin.host}`;
|
||||||
mixin.secondary_host = config.secondary_url.substr(config.secondary_url.indexOf('://') + 3);
|
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.secondary_scheme = config.secondary_url.substr(0, config.secondary_url.indexOf('://'));
|
||||||
mixin.api_url = `${mixin.scheme}://api.${mixin.host}`;
|
mixin.api_url = `${mixin.scheme}://api.${mixin.host}`;
|
||||||
mixin.auth_url = `${mixin.scheme}://auth.${mixin.host}`;
|
mixin.auth_url = `${mixin.scheme}://auth.${mixin.host}`;
|
||||||
|
@ -14,11 +14,6 @@ import vhost = require('vhost');
|
|||||||
import log from './log-request';
|
import log from './log-request';
|
||||||
import config from './conf';
|
import config from './conf';
|
||||||
|
|
||||||
function extractHostname(host) {
|
|
||||||
const index = host.indexOf(':');
|
|
||||||
return index < 0 ? host : host.substr(0, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init app
|
* Init app
|
||||||
*/
|
*/
|
||||||
@ -58,11 +53,9 @@ app.use((req, res, next) => {
|
|||||||
/**
|
/**
|
||||||
* Register modules
|
* Register modules
|
||||||
*/
|
*/
|
||||||
const hostname = extractHostname(config.host);
|
app.use(vhost(`api.${config.hostname}`, require('./api/server')));
|
||||||
const secondaryHostname = extractHostname(config.secondary_host);
|
app.use(vhost(config.secondary_hostname, require('./himasaku/server')));
|
||||||
app.use(vhost(`api.${hostname}`, require('./api/server')));
|
app.use(vhost(`file.${config.secondary_hostname}`, require('./file/server')));
|
||||||
app.use(vhost(secondaryHostname, require('./himasaku/server')));
|
|
||||||
app.use(vhost(`file.${secondaryHostname}`, require('./file/server')));
|
|
||||||
app.use(require('./web/server'));
|
app.use(require('./web/server'));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user