diff options
| author | Acid Chicken (硫酸鶏) <root@acid-chicken.com> | 2019-02-04 02:06:08 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-04 02:06:08 +0900 |
| commit | cf9e8ed39ec2acd098ba3587f0957a6afa641a74 (patch) | |
| tree | 1a04575766ff3a20b67c2f187b598fb660ca7e2f | |
| parent | Bye 'is-url' (diff) | |
| download | sharkey-cf9e8ed39ec2acd098ba3587f0957a6afa641a74.tar.gz sharkey-cf9e8ed39ec2acd098ba3587f0957a6afa641a74.tar.bz2 sharkey-cf9e8ed39ec2acd098ba3587f0957a6afa641a74.zip | |
Update load.ts
| -rw-r--r-- | src/config/load.ts | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/config/load.ts b/src/config/load.ts index fc3e699199..904305647d 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -47,14 +47,21 @@ export default function load() { return Object.assign(config, mixin); } -function validateUrl(url: string) { +function tryCreateUrl(url: string) { try { return new URL(url); } catch (e) { - throw `url="${url}" is not a valid URL`; + throw `url="${url}" is not a valid URL.`; } } +function validateUrl(url: string) { + const result = tryCreateUrl(url); + if (result.pathname.trim('/').length) throw `url="${url}" is not a valid URL, has a pathname.`; + if (!url.includes(result.host)) throw `url="${url}" is not a valid URL, has an invalid hostname.`; + return result; +} + function normalizeUrl(url: string) { return url.endsWith('/') ? url.substr(0, url.length - 1) : url; } |