Skip to content

Commit 1f1a7ce

Browse files
authored
Revert "Port method and path fixes - can overwrite autogenerated routes - sticks to its http methods (#6)" (#9)
This reverts commit 9a73dc9.
1 parent 9a73dc9 commit 1f1a7ce

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

src/adapters/controllers/post-invoke-port.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ export default function anyInvokePortFactory (invokePort) {
1313
const result = await invokePort({
1414
port: httpRequest.params.port,
1515
args: httpRequest.body,
16-
method: httpRequest.method,
17-
headers: httpRequest.headers,
18-
path: httpRequest.path,
1916
id: httpRequest.params.id || null
2017
})
2118

src/aegis.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,11 @@ const router = {
9696
if (ctrl.ports) {
9797
for (const portName in ctrl.ports) {
9898
const port = ctrl.ports[portName]
99-
const specPortMethods = (port?.methods || "").join('|')
100-
10199
if (port.path) {
102100
routeOverrides.set(port.path, portName)
103101
}
104102

105-
if (checkAllowedMethods(ctrl, method) && (!port.methods || (specPortMethods.includes(method.toLowerCase()))) ) {
103+
if (checkAllowedMethods(ctrl, method)) {
106104
routes.set(port.path || path(ctrl.endpoint), {
107105
[method]: adapter(ctrl.fn)
108106
})
@@ -133,8 +131,6 @@ const router = {
133131
}
134132

135133
function makeRoutes () {
136-
router.adminRoute(getConfig, http)
137-
router.userRoutes(getRoutes)
138134
router.autoRoutes(endpoint, 'get', liveUpdate, http)
139135
router.autoRoutes(endpoint, 'get', getModels, http)
140136
router.autoRoutes(endpoint, 'post', postModels, http)
@@ -150,6 +146,8 @@ function makeRoutes () {
150146
router.autoRoutes(endpointPortId, 'patch', anyInvokePorts, http, true)
151147
router.autoRoutes(endpointPortId, 'delete', anyInvokePorts, http, true)
152148
router.autoRoutes(endpointPortId, 'get', anyInvokePorts, http, true)
149+
router.adminRoute(getConfig, http)
150+
router.userRoutes(getRoutes)
153151
console.log(routes)
154152
}
155153

src/domain/use-cases/invoke-port.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,23 @@ export default function makeInvokePort ({
3333
}
3434
/**
3535
*
36-
* @param {{id:String,model:import('..').Model,args:String[],port:String,method:String,headers:Array}} input
36+
* @param {{id:string,model:import('..').Model,args:string[],port:string}} input
3737
* @returns
3838
*/
3939
return async function invokePort (input) {
4040
if (isMainThread) {
4141
return threadpool.runJob(invokePort.name, input, modelName)
4242
} else {
4343
try {
44-
let { id = null, port = null, method, path } = input;
44+
let { id = null, port = null} = input;
4545
const service = await findModelService(id)
4646
if (!service) {
4747
throw new Error('could not find a service associated with given id')
4848
}
4949

50-
const specPorts = service.getPorts();
5150
if(!port) {
51+
const specPorts = service.getPorts();
52+
const path = context['requestContext'].getStore().get('path');
5253
for(const p of Object.entries(specPorts)) {
5354
if(!p[1].path) {
5455
continue;
@@ -67,14 +68,6 @@ export default function makeInvokePort ({
6768
throw new Error('the port or record ID is invalid')
6869
}
6970

70-
const specPortMethods = specPorts[port]?.methods.join('|').toLowerCase();
71-
if (specPortMethods && !(specPortMethods.includes(method.toLowerCase()))) {
72-
throw new Error('invalid method for given port');
73-
}
74-
if (specPorts[port]?.path && !pathsMatch(specPorts[port].path, path)) {
75-
throw new Error('invalid path for given port');
76-
}
77-
7871
return await service[port](input)
7972
} catch (error) {
8073
return AppError(error)

0 commit comments

Comments
 (0)