Skip to content

Commit

Permalink
fix: subdomain and domain detection will work with second level hiera…
Browse files Browse the repository at this point in the history
…chy TLD
  • Loading branch information
gerard2perez committed Nov 4, 2017
1 parent fad1db0 commit d40ef48
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -107,10 +108,10 @@
}
},
"nyc": {
"lines": 99,
"statements": 99,
"functions": 99,
"branches": 99,
"lines": 100,
"statements": 100,
"functions": 100,
"branches": 100,
"reporter": [
"lcov",
"text"
Expand All @@ -126,7 +127,7 @@
"sourceMap": false,
"instrument": false,
"cache": true,
"check-coverage": false,
"check-coverage": true,
"all": false,
"report-dir": "./coverage"
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
12 changes: 9 additions & 3 deletions src/middleware/subdomainrouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions src/support/KoatonRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/support/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit d40ef48

Please sign in to comment.