Skip to content

Commit

Permalink
(add) resources to export
Browse files Browse the repository at this point in the history
(fix) export loading router
  • Loading branch information
jstty committed Aug 19, 2016
1 parent 5fa9388 commit 3da5910
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ HelloCtrl.prototype.world = function()
{
return this.data;
};

// localhost:8000/test
HelloCtrl.prototype.test = function(util)
{
return util.test();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

module.exports = {
'util': require('./util')
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@ module.exports = [
method: {
get: "world" // defined in controller module"
}
},
{
api: "/test",
controller: "hello", // default "<service.directory>/controllers/<controller>.js"
method: {
get: "test" // defined in controller module"
}
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

function Util(){
}

Util.prototype.test = function(){
return { 'test': 123 };
};

module.exports = Util;
21 changes: 17 additions & 4 deletions legacy/manager.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,13 @@ ServiceManager.prototype._loadServices = function () {
service.routes = serviceManifest.routes || {};
service.preRoutes = serviceManifest.preRoutes || {};
service.controller = serviceManifest.controller || {};
service.directory = serviceManifest.directory || { service: "", controllers: "", resolvers: "", views: "", static: "" };
service.directory = serviceManifest.directory || {
service: "",
controllers: "",
resolvers: "",
views: "",
static: ""
};
service.resolver = {};
service.resources = {};

Expand Down Expand Up @@ -312,6 +318,12 @@ ServiceManager.prototype._loadServices = function () {
logger.groupEnd(" ");
}

if (serviceManifest.resources) {
_.forEach(serviceManifest.resources, function (resourceModule, name) {
this.addResource(name, resourceModule, 'factory', service);
}.bind(this));
}

// wait for Q'd resources to resolve before letting service resolve
if (service._promiseQueue.length) {
//logger.info("Wait for Setup...");
Expand Down Expand Up @@ -347,7 +359,7 @@ ServiceManager.prototype.postStartInit = function () {

service._promiseQueue = [];

if (_.isFunction(service.instance.$postStartInit)) {
if (service.instance && _.isFunction(service.instance.$postStartInit)) {
try {
var result = this._injectionDependency(module, service, service.instance, service.instance.$postStartInit);

Expand All @@ -362,7 +374,7 @@ ServiceManager.prototype.postStartInit = function () {
}

_.forEach(service.resources, function (resource) {
if (_.isFunction(resource.instance.$postStartInit)) {
if (resource.instance && _.isFunction(resource.instance.$postStartInit)) {
try {
var result = this._injectionDependency(module, service, resource.instance, resource.instance.$postStartInit);

Expand Down Expand Up @@ -854,12 +866,13 @@ ServiceManager.export = function (serviceName) {
// console.log('dirname:', __dirname, ', cwd:', process.cwd());
// console.log('filePath:', filePath, ', parts:', parts);

// service struction
// service structure
var service = {
name: serviceName,
config: util.require([filePath + path.sep + serviceName + '.config.json', filePath + path.sep + serviceName + '.config.js']),
module: util.require(filePath + path.sep + serviceName + '.js'),
routes: util.require([filePath + path.sep + serviceName + '.routes.json', filePath + path.sep + serviceName + '.routes.js']),
resources: util.require([filePath + path.sep + serviceName + '.resources.json', filePath + path.sep + serviceName + '.resources.js']),
controller: {}
};

Expand Down
Loading

0 comments on commit 3da5910

Please sign in to comment.