From 4c9bcf2ab42401af79348f10106dc9006a7ba2a2 Mon Sep 17 00:00:00 2001 From: rinsuki <428rinsuki+git@gmail.com> Date: Mon, 26 Mar 2018 13:57:28 +0900 Subject: [PATCH] using WHATWG URL API --- src/config.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index 09e06f331..23feadc73 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'); @@ -128,11 +129,12 @@ 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); 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.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);