diff --git a/package.json b/package.json index 6025c81..c3395cd 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "codelive": "npm-run-all --parallel export:live eslint:live", "codeclimate:report": "codeclimate-test-reporter < coverage/lcov.info", "commit": "git add -A & git-cz", - "semantic-release": "semantic-release pre && npm publish && semantic-release post" + "semantic-release": "semantic-release pre && npm publish && semantic-release post", + "precommit": "npm run eslint && npm run cover" }, "files": [ "scripts", @@ -107,10 +108,10 @@ } }, "nyc": { - "lines": 99, - "statements": 99, - "functions": 99, - "branches": 99, + "lines": 100, + "statements": 100, + "functions": 100, + "branches": 100, "reporter": [ "lcov", "text" @@ -126,7 +127,7 @@ "sourceMap": false, "instrument": false, "cache": true, - "check-coverage": false, + "check-coverage": true, "all": false, "report-dir": "./coverage" }, diff --git a/src/index.js b/src/index.js index 16a0113..693b265 100644 --- a/src/index.js +++ b/src/index.js @@ -29,7 +29,7 @@ import * as helmet from 'koa-helmet'; import * as Koa from 'koa'; import * as path from 'path'; import * as fs from 'fs'; -// TODO: This setup is for legacy compability + /** @ignore */ let App = new Koa(), koaton = include(path.join(__dirname, 'middleware')); diff --git a/src/middleware/subdomainrouter.js b/src/middleware/subdomainrouter.js index 955e4d9..3c457ff 100644 --- a/src/middleware/subdomainrouter.js +++ b/src/middleware/subdomainrouter.js @@ -6,9 +6,15 @@ import { routers } from './router'; * @param {KoaNext} next */ export default async function subdomainrouter (ctx, next) { - let [subdomain = 'www'] = ctx.request.subdomains; - ctx.state.subdomain = subdomain; - ctx.subdomain = subdomain; + ctx.subdomain = 'www'; + for (const subdomain of configuration.server.subdomains) { + if (ctx.request.host.indexOf(subdomain) === 0) { + ctx.state.subdomain = subdomain; + ctx.subdomain = subdomain; + break; + } + } + ctx.state.domain = ctx.request.host.replace(`${ctx.subdomain}.`, ''); /* istanbul ignore next */ let origin = ctx.headers.origin ? ctx.headers.origin : ctx.request.origin; if (origin.indexOf(configuration.server.host) > -1) { diff --git a/src/support/KoatonRouter.js b/src/support/KoatonRouter.js index be735a1..d9218d3 100644 --- a/src/support/KoatonRouter.js +++ b/src/support/KoatonRouter.js @@ -144,7 +144,6 @@ export default class KoatonRouter { } catch (err) { debug(err); } - console.warn(content, actions); let action = DeepGet(content, ...actions) || DefaultView(controller); return action; } @@ -182,7 +181,6 @@ export default class KoatonRouter { let nroute = route[0] || 'home'; allroutes[this.subdomain] = allroutes[this.subdomain] || []; allroutes[this.subdomain].push([new RegExp(`^${exp || 'home'}$`), repl.replace(/\/+/g, '/')]); - // console.log(allroutes); (secured ? this.secured : this.public)[method](url, async (ctx, next) => { ctx.state.route = nroute; ctx.state.fullRoute = url; diff --git a/src/support/globals.js b/src/support/globals.js index 6684230..ea41983 100644 --- a/src/support/globals.js +++ b/src/support/globals.js @@ -60,7 +60,6 @@ global.ProyPath = function (...args) { return path.normalize(path.join.apply(path, args)); }; -// TODO I don't like this here process.env.NODE_PATH = path.join(process.cwd(), 'node_modules'); require('module').Module._initPaths();