summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-01-07 22:12:36 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-01-07 22:12:36 +0900
commit7e2c866575834ed220dbd2f18e1d2deefe13da12 (patch)
treedbe6704a543a8c827eb5a37b9f0b25737c8b4ebe /src
parentUpdate dependencies :rocket: (diff)
downloadsharkey-7e2c866575834ed220dbd2f18e1d2deefe13da12.tar.gz
sharkey-7e2c866575834ed220dbd2f18e1d2deefe13da12.tar.bz2
sharkey-7e2c866575834ed220dbd2f18e1d2deefe13da12.zip
Validate URLs
Diffstat (limited to 'src')
-rw-r--r--src/config.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/config.ts b/src/config.ts
index 2369b709fc..d6b1af0e35 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -4,6 +4,7 @@
import * as fs from 'fs';
import * as yaml from 'js-yaml';
+import * as isUrl from 'is-url';
/**
* ユーザーが設定する必要のある情報
@@ -72,6 +73,10 @@ export default (path: string) => {
const mixin: Mixin = {} as Mixin;
+ // Validate URLs
+ if (!isUrl(config.url)) urlError(config.url);
+ if (!isUrl(config.secondary_url)) urlError(config.secondary_url);
+
config.url = normalizeUrl(config.url);
config.secondary_url = normalizeUrl(config.secondary_url);
@@ -93,3 +98,8 @@ export default (path: string) => {
function normalizeUrl(url: string): string {
return url[url.length - 1] === '/' ? url.substr(0, url.length - 1) : url;
}
+
+function urlError(url: string): void {
+ console.error(`「${url}」は、正しいURLではありません。先頭に http:// または https:// をつけ忘れてないかなど確認してください。`);
+ process.exit();
+}