Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
djumanoff committed Nov 13, 2015
1 parent 8d12d87 commit 5a71a80
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 44 deletions.
20 changes: 6 additions & 14 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
'use strict';

var argv = require('touchka').argv;
var service = require('touchka').Service;
var port = argv.port || 3000;
var env = argv.env || 'dev';
var config = require('./config.json');
var name = require('./package.json').name;

var srv = service('referal_system');
var service = require('touchka-service').Service;
var port = config.port || 3000;
var env = config.env || 'dev';

var error = require('touchka').error;
var busy = require('busy');
srv.use(function(req, res, next) {
if (busy.blocked) {
return error(new Error("I'm busy right now, sorry."), res, 503);
} else {
next();
}
});
var srv = service(name);

if (env != 'dev') {
srv.use(require('./auth'));
Expand Down
5 changes: 3 additions & 2 deletions auth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

var error = require('touchka').error;
var CONTROL_PANEL_IP = require('touchka').argv.CONTROL_PANEL_IP || '::1';
var config = require('./config.json');
var error = require('touchka-service').error;
var CONTROL_PANEL_IP = config.CONTROL_PANEL_IP || '::1';

module.exports = function(req, res, next) {
var context = req.originalUrl.split('/');
Expand Down
44 changes: 44 additions & 0 deletions cli.help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module.exports = {
help: {
boolean: true,
describe: "Display this message."
},
port: {
alias: "p",
default: "3000",
describe: "Port used to lift the server."
},
env: {
default: "dev",
describe: "Environment in which to run the server."
},
DB_PORT: {
default: 27017,
describe: "Port of the mongodb server."
},
DB_HOST: {
default: '127.0.0.1',
describe: "Host of the mongodb server."
},
DB_USER: {
default: '',
describe: "User of the mongodb server."
},
DB_NAME: {
default: 'touchka-refsys',
describe: "Database of the mongodb server."
},
DB_PASS: {
default: '',
describe: "Password of the mongodb server."
},
ENTRYPOINT: {
alias: 'EP',
default: "http://localhost:3030",
describe: "Central endpoint for all services."
},
AUTH_URL: {
default: "http://localhost:3030",
describe: "URL of the auth server of drivers."
}
};
16 changes: 16 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"_": [],
"help": false,
"port": 10101,
"p": "3000",
"env": "dev",
"DB_PORT": 27017,
"DB_HOST": "127.0.0.1",
"DB_USER": "",
"DB_NAME": "touchka-refsys",
"DB_PASS": "",
"ENTRYPOINT": "http://localhost:3030",
"EP": "http://localhost:3030",
"AUTH_URL": "http://localhost:3030",
"$0": "index.js"
}
6 changes: 3 additions & 3 deletions context/code.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var router = require('touchka').Router();
var router = require('touchka-service').Router();
var async = require('async');
var error = require('touchka').error;
var ok = require('touchka').ok;
var error = require('touchka-service').error;
var ok = require('touchka-service').ok;

router

Expand Down
6 changes: 3 additions & 3 deletions context/entity.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var router = require('touchka').Router();
var router = require('touchka-service').Router();

var error = require('touchka').error;
var ok = require('touchka').ok;
var error = require('touchka-service').error;
var ok = require('touchka-service').ok;

router

Expand Down
9 changes: 5 additions & 4 deletions context/promo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
var router = require('touchka').Router();
var URL = require('touchka').argv.AUTH_URL || 'http://localhost:3030';
var config = require('../config.json');
var router = require('touchka-service').Router();
var URL = config.AUTH_URL || 'http://localhost:3030';

var error = require('touchka').error;
var ok = require('touchka').ok;
var error = require('touchka-service').error;
var ok = require('touchka-service').ok;

router

Expand Down
6 changes: 3 additions & 3 deletions context/reward.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var router = require('touchka').Router();
var router = require('touchka-service').Router();

var error = require('touchka').error;
var ok = require('touchka').ok;
var error = require('touchka-service').error;
var ok = require('touchka-service').ok;

router

Expand Down
10 changes: 6 additions & 4 deletions context/vendor.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
var router = require('touchka').Router();
var URL = require('touchka').argv.AUTH_URL || 'http://localhost:3030';
var router = require('touchka-service').Router();

var error = require('touchka').error;
var ok = require('touchka').ok;
var config = require('../config.json');
var URL = config.AUTH_URL || 'http://localhost:3030';

var error = require('touchka-service').error;
var ok = require('touchka-service').ok;

router

Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

require('touchka').bootstrap(function() {
require('touchka-bootstrap')(function() {
require('./app');
}, 4);
}, 4, function() {
require('touchka-argv')(require('./cli.help.js'), './config.json');
});
14 changes: 7 additions & 7 deletions init.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var mongoose = require('mongoose');
var argv = require('touchka').argv;
var config = require('./config.json');

var DB_HOST = argv.DB_HOST || '127.0.0.1';
var DB_PORT = argv.DB_PORT || '27017';
var DB_NAME = argv.DB_NAME || 'touchka-refsys';
var DB_USER = argv.DB_USER || '';
var DB_PASS = argv.DB_PASS || '';
var DB_OPTIONS = argv.DB_OPTIONS || '{ "poolSize": 5 }';
var DB_HOST = config.DB_HOST || '127.0.0.1';
var DB_PORT = config.DB_PORT || '27017';
var DB_NAME = config.DB_NAME || 'touchka-refsys';
var DB_USER = config.DB_USER || '';
var DB_PASS = config.DB_PASS || '';
var DB_OPTIONS = config.DB_OPTIONS || '{ "poolSize": 5 }';
var DB_URL = 'mongodb://' + DB_HOST + ':' + DB_PORT + '/' + DB_NAME;

module.exports = function() {
Expand Down
2 changes: 1 addition & 1 deletion models/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var CounterSchema = new Schema({
seq: { type: Number, default: 0 }
});

module.exports = function(conn) {
module.exports = function(conn) {
var Counter = conn.model('Counter', CounterSchema);

Counter.getId = function(entity, callback) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "node test",
"start": "node index --port=80 --env=dev --DB_HOST=10.0.4.55"
"start": "forever index.js --port=80 --env=dev --DB_HOST=10.0.4.55"
},
"keywords": [
"Referal",
Expand Down

0 comments on commit 5a71a80

Please sign in to comment.