#68 - Implement shorthand notation for middleware paths#70
Conversation
|
Two suggestions:
loopback/index.js
|
FWIW, Why is
Please open a new GH issue to track this requirement. |
|
I'm following the url pattern. |
Using the same logic, We can use |
|
@raymondfeng Can we agree that |
|
@bajtos I would prefer not to add resolution magic if the path is for
|
|
I can see the value in your proposal too. @ritch, could you chime in and let us know your opinion too? If you agree with @raymondfeng, then I will rework my pull request to implement his proposal. I am not sure if it is a good thing to use |
|
Actually, if this is a blocker for you @raymondfeng, then it would be best if you could take this over, as I won't have time to finish this until Monday (most likely). |
|
One last though: later, when we enhance loopback-workspace, Arc and loopback-generator to offer a configuration UI based on metadata provided by middleware in some JSON file, we won't be able to infer the config properties for the middleware referenced via |
|
I can rework the PR to move forward. |
|
IMO // long form (allows you to explicitly pass to require)
// detected when a `#` is not present
"loopback/middleware/rest"
// short form (opts into our middleware search algorithm)
"loopback#rest"The short form precedence should be:
Note: this excludes support for |
|
@ritch I think |
2806b4d to
6b86b17
Compare
|
The code has been updated to reflect: // long form (allows you to explicitly pass to require)
// detected when a `#` is not present
"loopback/middleware/rest"
// short form (opts into our middleware search algorithm)
"loopback#rest"The short form precedence should be:
Note: this excludes support for |
|
FYI: I was able to bring up strong-gateway using https://github.com/strongloop/strong-gateway/blob/feature/externalize-middleware/server/middleware.json. |
|
One more thought to consider: how are we going to handle |
There was a problem hiding this comment.
Please don't use /**, that's indicating a jsdoc comment. Use plain comment /* instead.
|
@raymondfeng please add two more tests:
Is there any reason why we are not supporting |
6b86b17 to
7a40224
Compare
|
@bajtos I fixed the code to honor |
Hmm, that's a good point. This is a problem similar to strongloop/loopback#833. A possible solution is to use |
There was a problem hiding this comment.
Commented-out code - please remove it. If you feel it should serve as a todo, then annotate it with a todo comment explaining that intent.
|
Comments addressed. |
There was a problem hiding this comment.
Why is it necessary to trim the value?
There was a problem hiding this comment.
No harm to trim it, for example, " ./lib/x": {} will be supported.
There was a problem hiding this comment.
We don't trim any other values anywhere else in loopback. I prefer to be consistent and either trim all values or none. Since this is the first place, I am proposing to remove this line and implement trimming in a new pull request if you are convinced it is a good feature (I am personally not).
|
@raymondfeng What's your opinion on the following? Do you feel like fixing it in this PR, or is it out of scope?
|
fde3970 to
cb07de7
Compare
|
My preference is merge the PR and create an issue to add the ability to test execution against an embedded sandbox app. |
Sounds good, please create the issue before we merge the PR. |
cb07de7 to
f781937
Compare
|
The PR is still missing the two tests I mentioned in my earlier comment:
|
f781937 to
d3a5d58
Compare
|
I added the tests and keep it disabled for now until #73 is fixed. LGTY now? |
There was a problem hiding this comment.
I am missing check that loopback#static was configured.
I strongly dislike keeping around commented-out code (my-module#myMiddleware), just remove it and add it back as part of #73.
As for testing my-module#myMiddleware syntax, you can surely use loopback#errorHandler or loopback#favicon, as that should already work now, even without #73? You will need a different HTTP request to ensure the middleware was executed, therefore it is better to move this stuff to a different test (a new it() block).
d3a5d58 to
bed6ba7
Compare
|
Enhanced the tests and added |
There was a problem hiding this comment.
What is the point of this block? I does not seem to be used by the test code below.
When the middleware name (path) is in the format {module}#{filename},
loopback-boot resolves the path by trying multiple locations and
using the first one that exists:
- {module} and check the {filename} property of the exports
-> e.g. loopback.rest
- {module}/server/middleware/{filename}
-> e.g. loopback/server/middleware/rest
- {module}/middleware/{filename}
-> e.g. loopback/middleware/rest
Values in any other format will bypass this resolution algorithm and
they will be used in the original form:
- a full path in a module: loopback/server/middleware/rest
- a relative path: ./middleware/custom, ./custom, ../logger
- an absolute path: /usr/local/lib/node_modules/compression
bed6ba7 to
2f72006
Compare
|
I have addressed the comments myself and amended the commit. |
|
@slnode test please |
#68 - Implement shorthand notation for middleware paths
When the middleware name (path) is in the format {module}/{filename},
loopback-boot resolves the path by trying multiple locations and
using the first one that exists:
-> e.g. loopback/rest
-> e.g. loopback/middleware/rest
-> e.g. loopback/server/middleware/rest
Values in any other format will bypass this resolution algorithm and
they will be used in the original form:
Close #68
/to @ritch please review
/cc @raymondfeng