diff options
| author | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2019-02-05 19:54:41 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-05 19:54:41 +0900 |
| commit | 3e89dc603d85feb54e5236991713c87e38f6caa9 (patch) | |
| tree | 9034e6d2360028c92cd036304baa7b1a4f8cc1aa /src | |
| parent | 10.82.0 (diff) | |
| parent | Revert "Update load.ts" (diff) | |
| download | misskey-3e89dc603d85feb54e5236991713c87e38f6caa9.tar.gz misskey-3e89dc603d85feb54e5236991713c87e38f6caa9.tar.bz2 misskey-3e89dc603d85feb54e5236991713c87e38f6caa9.zip | |
Bye 'is-url' (#4113)
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/load.ts | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/config/load.ts b/src/config/load.ts index ba8b4af3ce..fc3e699199 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -6,7 +6,6 @@ import * as fs from 'fs'; import { URL } from 'url'; import * as yaml from 'js-yaml'; import { Source, Mixin } from './types'; -import isUrl = require('is-url'); import * as pkg from '../../package.json'; /** @@ -26,10 +25,7 @@ export default function load() { const mixin = {} as Mixin; - // Validate URLs - if (!isUrl(config.url)) throw `url="${config.url}" is not a valid URL`; - - const url = new URL(config.url); + const url = validateUrl(config.url); config.url = normalizeUrl(config.url); mixin.host = url.host; @@ -51,6 +47,14 @@ export default function load() { return Object.assign(config, mixin); } +function validateUrl(url: string) { + try { + return new URL(url); + } catch (e) { + throw `url="${url}" is not a valid URL`; + } +} + function normalizeUrl(url: string) { return url.endsWith('/') ? url.substr(0, url.length - 1) : url; } |