-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cors: name collision #58
Comments
baaah. found a workaround.
where
|
Ugh. Yeah, I'd strongly recommend not putting "node_modules" in the fittingsDirs because of the potential name conflicts. |
Oh... 😞 ...but I need fitting to be modular and reusable... What would you recommend? |
I'll give you more information. My task is to provide a repository of modular and reusable infrastructure parts to implement a big set of micro-services. On the surface, out of the premise - Pipes and Fittings look great for this purpose 😄. These infrasturcure parts may be:
This, on top of the must-for-all basics:
I thought that each pipe may enrich the context with an initiated module / instance, resulting with a context empowered with all the tools necessary for the job that gets passed to the web controller as declared by the programmer, probably in some x-uses property found on the mm. yea. I know - now the context is not passed to the web controller because the swagger_router passes The microservices must be slim: These tools must be cherry-picked into each project, where an initial boiler-plate will provide the barebones basics. I don't want to wrap every adapter in a node-machine. We already have our own solution for documentation and exploration. We aspire to work with simple node-modules. ... I'll appreciate any input. Osher |
You know what? Here's a rabbit hole I'd like your opinion about: Maybe we can explore it and get something good out of it. It will be fair if you say it's too soon for it, or too demanding for the schedule. It's a rabbit hole because it rises few design discussions, but I believe it worth's exploring. Ideally, there will be an operation level in the spirit of This pipe should be a pipe defined add-hock for the operation. If I have to switch all the time between So what does it give us? any thoughts? |
do I talk to much , or you really need time to conteplate all this? |
I haven't had much of a chance to think about this, but we're already pushing the boundaries of what Swagger (Open API) defines (it should basically just be the REST interface), so I'm not sure it's wise to dive even further down this programming language rabbit hole inside the Open API document. Note that Pipes and Fittings are already decoupled from web context. It's only the connect_middleware that knows how to translate the simple in/out of the pipe from a request and into a response. |
that's not quite true. one big difference is: the controller handlers are written for both alternative feel wrong... do you get to see what I mean? if operation handlers would get to be written for The ctx will have Now this will truly decouple them from the web-context :) On Mon, Sep 19, 2016 at 11:39 PM, Scott Ganyo [email protected]
|
I'm still trying to understand your use-case and I think I'm failing, so forgive me if I over-simplify (or get it completely wrong), but what I'm gathering is that you'd like to do something like this: swagger-node-runner -> pipe -> [middleware] -> pipe -> swagger-node-runner Where you'd be plugging in some existing controllers that uses the standard (req, res, next) function as [middleware]. But you also don't want to wrap your controllers in fittings. Am I completely off-base? Sorry if so... Maybe it would help me to understand if we were discussing one simple, concrete example. |
mm. let me illustrate. infra packates:
basically, all you need to keep your controllers slim, logical and free from implementation details about contexts:Decoupling user-code and infra pkgs mean that I can use them in any other context: msg-queue-consumer, TCP server - you name it. I really adore the idea of bagpipes, I actually started designing one for my own just before I discovered it inside swagger-node-runner, and realizing the potential of this - _my brain exploded!!_ I was so happy that there are other good people that think like me 😄 |
mmm. there are still open questions re. how decoupled should the execution context and the web context be. But I foresee a stage where we'll have to really decouple them - maybe because of name collisions, maybe because of other reasons - but we'll have to be creating a private focused context for the execution. For this we'll have to decide how to indicate what tools that are initiated once in the router pipe = i.e. are put on the router web context, but should be passed to the execution context. By when that time comes - I trust we'll have few projects running over this structure, and we'll figure the right balance from observing what we got. |
P.S. I just found that some people answer comments right from the mail, where I often use the comments like an editor: I often "upgrade" my comments - simply because github allows it, and I don't know if github informs participants when a message is edited. Anyway - bottom line - final messages on the github web. |
im considering using my own router fitting - a lightly hacked version of the router of the runner - and avoiding the |
Fantastic! A picture is worth ~1k words! Thanks! I (finally) think I understand where you're going. So to kind of summarize back into prose: Based on your desired state, you'd prefer a direct mapping to pipes you've built for the security and router fittings. Correct? Let me think on this a bit... |
yes - this summary is much more on target :) but lets start with the obvious:
So. Having that said - we can distinct the following following levels:
In this stage I did not find a use-case for post-operation. post-path, post-all fitting, but I'm sure that if the need comes - we'll find how to feature it in an elegant way 😉 . I'm happy you want to give it a thought. However - I noted the time differences between us. Cheers!! |
Great! First off, though, I want to make sure we set a baseline:
Assuming those two statements are correct, it seems like the scope of what we'd need to address for your use case could be reduced quite a bit. That said, I think it might make sense to break the discussion apart into two general areas of potential improvement (or at least we should consider these as related, but not interdependent items):
Am I still missing something here? |
I think we're quite on target! I tried Next - Ah - pipe composition is something I did not consider. This opens some possibilities. About pt. 2 - I propose to support both functionalities side by side as passing to the controllers I think I can put up a PR with the configuration flag option, based on something in the spirit of:
thoughts? |
Hey! Sorry for the delay. So, glad the composition sounds like it may work for you. So... on part two... I wonder if this could happen automagically using, say, |
I'm still thinking about it, so lets express some thoughts in write, and consider if all of them is a desired effect, and see if it all makes sense. The biggest implication I can point in this stage is: I see greater values for this especially if we open the possibilities to use pipes from the node_modules - i.e. - use as a pipe a package that exports a middleware function by naming that package name as a fitting in a compound pipe (and on the same breath we get for free support for packages that exports a mw-factory that accepts a sinlge config object 😄, if you see what I mean here). But. It will also mean that there will not ever be any other future controller-type that accepts 3 arguments that is not a middleware, and no other future controller-type that will accept 2 arguments that is not made for It also means that the returned functions will have to explicitly name their args to ensure they answer the If we're on the same page - I think we have a design 😉 |
Yup. I totally, agree. There are potential issues, but...
It's the "no tricks" thing is the one that gives me a bit of heartburn - it's hard to put restrictions on things you can't control (and the node_modules issue is actually a good example of this). But, it does feel like the flexibility gained by this could be worth it. |
Roger. |
So say we all. |
I'll have a window for this, hopefully in a matter of days. A colleague architect pointed my attention that many developers write just I suggest to support the following:
config search stops on first find according to the following fallback chain:
Thoughts? |
Oh curse those lazy developers! ;) So... I'm going to reverse myself, and say that we should rely on the config annotations instead of auto-detect because it could be a breaking-change for some folks. (It's what I should've said in the first place anyway.) That said.. if you'd still like that mix-and-match auto-detect feature, we could have that if we simply add an "auto" config option. So we'd have: "middleware", "pipe", and "auto"... currently, of course, it's always "middleware" and we continue to default to that so as not to break anything. "pipe" sets it to pipe, natch. And "auto" sets it to use its best judgement with .length... and it's up to the developer to ensure that things don't break. Do you think this is worthwhile? The config search chain looks good. |
I feel much safer with your new decision. That makes me happy 😄 |
Oups. Forgot something. So, update to config search. Still stops on first find.
How would you suggest to handle illegal values? We can validate point 4 during start-up. That's very easy. If there is an easy reference to the Otherwise - I can offer the following, relaying on runtime behavior:
A more harsh approach is emit an error and passing an error to the callback. What is it going to be? |
mmm. Found it
In this case I can optimize and load each operation with it's final value instead of searching the value for every operation execution |
I'm not sure where you are working, but in most places in swagger-node-runners's index.js, it's just |
The PR is not ready, but you can have an early look. |
Ok. the PR is on a good state, although I'd rather do 2 more things there. |
I'm trying to create some reusable pipe fittings packed as simple npm packages.
So to prove the concept I placed a simple
node_modules/required-fitting/index.js
(together with a standardpackage.json
) in same folder, as follows:And added to the config:
So:
Alas - the pipe explodes. The error is observed on the response as
{"message":"undefined is not a function"}
, with NO MENTION of it on the server logIt appears to explode on
cors
, which is now ambiguous between the two paths:node_modules/cors
lib/fitting/cors.js
playing with order of paths in
fittingsDir
did not help :(I can PR to rename
lib/fitting/cors.js
tolib/fitting/swagger_cors.js
or anytihng of that sort, however, it looks like a breaking change.I think the situation points also to an additional problem:
I think the fitting builder that calls the fitting factory may be required to make sure that the factory returns a function in the correct arity. (the vanilla
cors
package is af(1)
factory that returnsf(3)
)I did not miss the part about
type:node-machine
that requires some overhead plus pushes me to experimental zone, which I would totally prefer to avoid at this stage... my client wont approve of anything with experimental labelled on it...Thoughts?
The text was updated successfully, but these errors were encountered: