Skip to content

Commit

Permalink
Refactored server to use controllers from another structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
kallaspriit committed Apr 12, 2016
1 parent 2b1bacf commit 6c31223
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions controllers/user/index.js → controllers/UserController.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AbstractController from '../../lib/server/AbstractController';
import Errors from '../../errors';
import AbstractController from '../lib/server/AbstractController';
import Errors from '../errors';
import joi from 'joi';

export default class UserController extends AbstractController {
Expand Down
11 changes: 9 additions & 2 deletions lib/server/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import restify from 'restify';
import bodyParser from 'body-parser';
import normalizeType from 'normalize-type';
import HttpStatus from 'http-status';
import changeCase from 'change-case';
import Errors from '../../errors';
import logger from '../logger';

Expand Down Expand Up @@ -119,7 +120,7 @@ export default class Server {
}

getControllersInDirectory(directory) {
const controllersPattern = path.join(directory, '**/*.js');
const controllersPattern = path.join(directory, '**/*Controller.js');
const controllerFilenames = glob.sync(controllersPattern);

return controllerFilenames.map((controllerFilename) => {
Expand All @@ -137,8 +138,14 @@ export default class Server {
getControllerNameFromFilename(filename) {
const info = path.parse(filename);
const directoryTokens = info.dir.split('/');
const basename = info.base;
const suffix = 'Controller.js';
const namePascalCase = basename.substr(0, basename.length - suffix.length);
const nameParamCase = changeCase.paramCase(namePascalCase);

return directoryTokens[directoryTokens.length - 1];
log('getControllerNameFromFilename', filename, nameParamCase);

return nameParamCase;
}

setupControllers() {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"body-parser": "^1.15.0",
"bunyan": "^1.8.0",
"bunyan-slack": "0.0.10",
"change-case": "^2.3.1",
"colors": "^1.1.2",
"cors": "^2.7.1",
"express": "^4.13.4",
Expand Down

0 comments on commit 6c31223

Please sign in to comment.