From dc351ef396b9c0780e2e8c46bc9174e411098de3 Mon Sep 17 00:00:00 2001
From: Akihiko Odaki <nekomanma@pixiv.co.jp>
Date: Sun, 25 Mar 2018 22:49:30 +0900
Subject: [PATCH] Pass hostname instead of host to vhost module

---
 src/server.ts | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/server.ts b/src/server.ts
index a2165d672b..84e8c41489 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -14,6 +14,11 @@ import vhost = require('vhost');
 import log from './log-request';
 import config from './conf';
 
+function extractHostname(host) {
+	const index = host.indexOf(':');
+	return index < 0 ? host : host.substr(0, index);
+}
+
 /**
  * Init app
  */
@@ -53,9 +58,11 @@ app.use((req, res, next) => {
 /**
  * Register modules
  */
-app.use(vhost(`api.${config.host}`, require('./api/server')));
-app.use(vhost(config.secondary_host, require('./himasaku/server')));
-app.use(vhost(`file.${config.secondary_host}`, require('./file/server')));
+const hostname = extractHostname(config.host);
+const secondaryHostname = extractHostname(config.secondary_host);
+app.use(vhost(`api.${hostname}`, require('./api/server')));
+app.use(vhost(secondaryHostname, require('./himasaku/server')));
+app.use(vhost(`file.${secondaryHostname}`, require('./file/server')));
 app.use(require('./web/server'));
 
 /**