Skip to content

Commit f6d4512

Browse files
committed
[fix] normalize prefix to standard
1 parent de4b4b3 commit f6d4512

File tree

5 files changed

+43
-31
lines changed

5 files changed

+43
-31
lines changed

lib/routes.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
export const Routes = {
22
'/{model}': {
3+
config: {
4+
prefix: 'tapestries.prefix'
5+
},
36
'POST': 'TapestryController.create'
47
},
58
'/{model}/{id?}': {
9+
config: {
10+
prefix: 'tapestries.prefix'
11+
},
612
'GET': 'TapestryController.find',
713
'PUT': 'TapestryController.update',
814
'PATCH': 'TapestryController.update',
915
'DELETE': 'TapestryController.destroy'
1016
},
1117
'/{parentModel}/{parentId}/{childAttribute}': {
18+
config: {
19+
prefix: 'tapestries.prefix'
20+
},
1221
'POST': 'TapestryController.createAssociation'
1322
},
1423
'/{parentModel}/{parentId}/{childAttribute}/{childId?}': {
24+
config: {
25+
prefix: 'tapestries.prefix'
26+
},
1527
'GET': 'TapestryController.findAssociation',
1628
'PUT': 'TapestryController.updateAssociation',
1729
'DELETE': 'TapestryController.destroyAssociation'

lib/utils.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ export const Utils = {
2525
return [...configIgnore, ...defaultIgnore]
2626
},
2727

28-
/**
29-
* Get either the configured spool-tapestries prefix, or use the one set by spool-router if any.
30-
*/
31-
getPrefix(app: FabrixApp) {
32-
let prefix = app.config.get('tapestries.prefix')
33-
if (!prefix) {
34-
prefix = app.config.get('router.prefix') || ''
35-
}
36-
return prefix.toString()
37-
},
28+
// /**
29+
// * Get either the configured spool-tapestries prefix, or use the one set by spool-router if any.
30+
// */
31+
// getPrefix(app: FabrixApp) {
32+
// let prefix = app.config.get('tapestries.prefix')
33+
// if (!prefix) {
34+
// prefix = app.config.get('router.prefix') || ''
35+
// }
36+
// return prefix.toString()
37+
// },
3838
/**
3939
* Compile controller handlers into route objects
4040
*/
@@ -49,12 +49,12 @@ export const Utils = {
4949
Utils.getControllerIgnore(app)
5050
)
5151

52-
const prefix = Utils.getPrefix(app)
52+
// const prefix = Utils.getPrefix(app)
5353
const routes = {}
5454
Object.keys(controllers).forEach((controllerName: string) => {
5555
controllers[controllerName].methods.forEach(handlerName => {
5656
const route = {}
57-
const path = Utils.getHandlerPath(app, prefix, controllers[controllerName].id, handlerName)
57+
const path = Utils.getHandlerPath(app, controllers[controllerName].id, handlerName)
5858

5959
Utils.getControllerMethods(app).forEach(method => {
6060
route[method] = Utils.getControllerHandler(controllerName, handlerName)
@@ -71,7 +71,7 @@ export const Utils = {
7171
*/
7272
getModelTapestries (app: FabrixApp): {[key: string]: any} {
7373
const actionsConfig = app.config.get('tapestries.models.actions') || {}
74-
const prefix = Utils.getPrefix(app)
74+
// const prefix = Utils.getPrefix(app)
7575
const routes = {}
7676
Object.keys(Routes).forEach(path => {
7777
Object.keys(Routes[path]).map(m => {
@@ -81,7 +81,7 @@ export const Utils = {
8181
}
8282
}
8383
})
84-
routes[`${prefix}${path}`] = Routes[path]
84+
routes[`${path}`] = Routes[path]
8585
})
8686
return routes
8787
},
@@ -103,7 +103,7 @@ export const Utils = {
103103
/**
104104
* Join a list as a path
105105
*/
106-
getHandlerPath (app: FabrixApp, prefix: string, controllerId: string, handlerName: string): string {
107-
return join('/', prefix, controllerId, handlerName)
106+
getHandlerPath (app: FabrixApp, controllerId: string, handlerName: string): string {
107+
return join('/', controllerId, handlerName)
108108
}
109109
}

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fabrix/spool-tapestries",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "Spool - Tapestries, Easy RESTful Services",
55
"scripts": {
66
"build": "tsc -p ./lib/tsconfig.release.json",
@@ -49,8 +49,8 @@
4949
"lodash": "^4.17.10"
5050
},
5151
"devDependencies": {
52-
"@fabrix/fabrix": "^1.1.1",
53-
"@fabrix/spool-router": "^1.1.2",
52+
"@fabrix/fabrix": "^1.1.2",
53+
"@fabrix/spool-router": "^1.1.3",
5454
"@fabrix/lint": "^1.0.0-alpha.3",
5555
"@types/lodash": "^4.14.109",
5656
"@types/node": "~10.3.4",
@@ -64,8 +64,8 @@
6464
"typescript": "~2.8.1"
6565
},
6666
"peerDependencies": {
67-
"@fabrix/fabrix": "^1.1.1",
68-
"@fabrix/spool-router": "^1.1.2"
67+
"@fabrix/fabrix": "^1.1.2",
68+
"@fabrix/spool-router": "^1.1.3"
6969
},
7070
"license": "MIT",
7171
"bugs": {

test/integration/util.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ describe('lib.Util', () => {
99
describe('#getHandlerPath', () => {
1010
it('should return correct url path for controller handler', () => {
1111
assert.equal(
12-
lib.Utils.getHandlerPath(global.app, '/prefix', 'test', 'test'),
13-
'/prefix/test/test'
12+
lib.Utils.getHandlerPath(global.app, '/prefix', 'test'),
13+
'/prefix/test'
1414
)
1515
})
1616
})
@@ -21,7 +21,7 @@ describe('lib.Util', () => {
2121
const tapestries = lib.Utils.getControllerTapestries(global.app)
2222
assert.equal(Object.keys(tapestries).length, 1)
2323
// assert(_.find(tapestries, {handler: 'TestController.testHandler'}))
24-
assert(tapestries[global.app.config.get('tapestries.prefix') + '/test/testHandler'])
24+
assert(tapestries['/test/testHandler'])
2525
})
2626

2727
it('should return an empty array if controller tapestry routes are disabled', () => {

0 commit comments

Comments
 (0)