diff --git a/lib/routes.ts b/lib/routes.ts index b19bc31..e609577 100755 --- a/lib/routes.ts +++ b/lib/routes.ts @@ -1,17 +1,29 @@ export const Routes = { '/{model}': { + config: { + prefix: 'tapestries.prefix' + }, 'POST': 'TapestryController.create' }, '/{model}/{id?}': { + config: { + prefix: 'tapestries.prefix' + }, 'GET': 'TapestryController.find', 'PUT': 'TapestryController.update', 'PATCH': 'TapestryController.update', 'DELETE': 'TapestryController.destroy' }, '/{parentModel}/{parentId}/{childAttribute}': { + config: { + prefix: 'tapestries.prefix' + }, 'POST': 'TapestryController.createAssociation' }, '/{parentModel}/{parentId}/{childAttribute}/{childId?}': { + config: { + prefix: 'tapestries.prefix' + }, 'GET': 'TapestryController.findAssociation', 'PUT': 'TapestryController.updateAssociation', 'DELETE': 'TapestryController.destroyAssociation' diff --git a/lib/utils.ts b/lib/utils.ts index b337e27..e6c66ad 100755 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -25,16 +25,16 @@ export const Utils = { return [...configIgnore, ...defaultIgnore] }, - /** - * Get either the configured spool-tapestries prefix, or use the one set by spool-router if any. - */ - getPrefix(app: FabrixApp) { - let prefix = app.config.get('tapestries.prefix') - if (!prefix) { - prefix = app.config.get('router.prefix') || '' - } - return prefix.toString() - }, + // /** + // * Get either the configured spool-tapestries prefix, or use the one set by spool-router if any. + // */ + // getPrefix(app: FabrixApp) { + // let prefix = app.config.get('tapestries.prefix') + // if (!prefix) { + // prefix = app.config.get('router.prefix') || '' + // } + // return prefix.toString() + // }, /** * Compile controller handlers into route objects */ @@ -49,12 +49,12 @@ export const Utils = { Utils.getControllerIgnore(app) ) - const prefix = Utils.getPrefix(app) + // const prefix = Utils.getPrefix(app) const routes = {} Object.keys(controllers).forEach((controllerName: string) => { controllers[controllerName].methods.forEach(handlerName => { const route = {} - const path = Utils.getHandlerPath(app, prefix, controllers[controllerName].id, handlerName) + const path = Utils.getHandlerPath(app, controllers[controllerName].id, handlerName) Utils.getControllerMethods(app).forEach(method => { route[method] = Utils.getControllerHandler(controllerName, handlerName) @@ -71,7 +71,7 @@ export const Utils = { */ getModelTapestries (app: FabrixApp): {[key: string]: any} { const actionsConfig = app.config.get('tapestries.models.actions') || {} - const prefix = Utils.getPrefix(app) + // const prefix = Utils.getPrefix(app) const routes = {} Object.keys(Routes).forEach(path => { Object.keys(Routes[path]).map(m => { @@ -81,7 +81,7 @@ export const Utils = { } } }) - routes[`${prefix}${path}`] = Routes[path] + routes[`${path}`] = Routes[path] }) return routes }, @@ -103,7 +103,7 @@ export const Utils = { /** * Join a list as a path */ - getHandlerPath (app: FabrixApp, prefix: string, controllerId: string, handlerName: string): string { - return join('/', prefix, controllerId, handlerName) + getHandlerPath (app: FabrixApp, controllerId: string, handlerName: string): string { + return join('/', controllerId, handlerName) } } diff --git a/package-lock.json b/package-lock.json index 3b4a775..79e78df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-tapestries", - "version": "1.1.2", + "version": "1.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -114,9 +114,9 @@ } }, "@fabrix/fabrix": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@fabrix/fabrix/-/fabrix-1.1.1.tgz", - "integrity": "sha512-CL06baNKFPUB5dFKVCtwgZzKNeQeJyXVwaZhs0JPe7hL/7+LhAZ8zmh0ugcva1YuXecGASp3zXuTdGODGhgCBA==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@fabrix/fabrix/-/fabrix-1.1.2.tgz", + "integrity": "sha512-pN0X58AUqw7QqN4phv3BBUcE6zoASEswg/YSQ6F4TJsJ0IQXPl7IhINB0tPs0RnJbWmO6uUhmeAjYIv/N27EcA==", "dev": true, "requires": { "lodash": "4.17.10", @@ -130,9 +130,9 @@ "dev": true }, "@fabrix/spool-router": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@fabrix/spool-router/-/spool-router-1.1.2.tgz", - "integrity": "sha512-a+EF5G8NCq9T5nP1Hn9nNzZWC306IEBA7Sh3Nt1DoziVCwOcd6lRMrvY7FdfLIi+I/TPqn5UC22GSQgd99N1Hw==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@fabrix/spool-router/-/spool-router-1.1.3.tgz", + "integrity": "sha512-fTgEDO2RcAi8TMPxcQWz6NkU/RLK8+givjEDgKCEutrM+K9Ib+DbY6MP+o/gNm1YZcsEJTksTPgtD19J9OavAA==", "dev": true, "requires": { "call": "5.0.1", diff --git a/package.json b/package.json index dc6f4a4..3317783 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@fabrix/spool-tapestries", - "version": "1.1.2", + "version": "1.1.3", "description": "Spool - Tapestries, Easy RESTful Services", "scripts": { "build": "tsc -p ./lib/tsconfig.release.json", @@ -49,8 +49,8 @@ "lodash": "^4.17.10" }, "devDependencies": { - "@fabrix/fabrix": "^1.1.1", - "@fabrix/spool-router": "^1.1.2", + "@fabrix/fabrix": "^1.1.2", + "@fabrix/spool-router": "^1.1.3", "@fabrix/lint": "^1.0.0-alpha.3", "@types/lodash": "^4.14.109", "@types/node": "~10.3.4", @@ -64,8 +64,8 @@ "typescript": "~2.8.1" }, "peerDependencies": { - "@fabrix/fabrix": "^1.1.1", - "@fabrix/spool-router": "^1.1.2" + "@fabrix/fabrix": "^1.1.2", + "@fabrix/spool-router": "^1.1.3" }, "license": "MIT", "bugs": { diff --git a/test/integration/util.test.js b/test/integration/util.test.js index 3cf946b..79ccc4f 100755 --- a/test/integration/util.test.js +++ b/test/integration/util.test.js @@ -9,8 +9,8 @@ describe('lib.Util', () => { describe('#getHandlerPath', () => { it('should return correct url path for controller handler', () => { assert.equal( - lib.Utils.getHandlerPath(global.app, '/prefix', 'test', 'test'), - '/prefix/test/test' + lib.Utils.getHandlerPath(global.app, '/prefix', 'test'), + '/prefix/test' ) }) }) @@ -21,7 +21,7 @@ describe('lib.Util', () => { const tapestries = lib.Utils.getControllerTapestries(global.app) assert.equal(Object.keys(tapestries).length, 1) // assert(_.find(tapestries, {handler: 'TestController.testHandler'})) - assert(tapestries[global.app.config.get('tapestries.prefix') + '/test/testHandler']) + assert(tapestries['/test/testHandler']) }) it('should return an empty array if controller tapestry routes are disabled', () => {