Comments (22)
+1 (I'd use this feature today)
from express-enrouten.
So the complexity here is that enrouten has no concept of config. Thinking this over, I think the simplest way to implement this would be to add another internal shortstop handler to confit
—similar to the config
handler—that would be replaced with a reference to the completely built config factory. That way, it could be passed as an argument (or option) to enrouten.
Just a thought.
from express-enrouten.
Yeah. Some sort of opaque thing passed in? If it's config, yay! when used by Kraken.
from express-enrouten.
Yep, this is a long time coming but really is a form of DI. As I start contemplating I welcome any thoughts or ideas.
EDIT: And yes, I'll start digging into your suggestion @jasisk.
from express-enrouten.
One thing that just occurred to me is that this will necessarily force a major version change (I was hoping it wouldn't). The current rule for directory
mode is that the traversal mechanism will only initialize files that accept a single argument, allowing route definitions to be intermingled with other files. By having user-defined arguments the mechanism for identifying those files becomes much more murky.
from express-enrouten.
Oh, that is just unfortunate!
from express-enrouten.
It may be a blessing in disguise. Gives us a little more latitude to take advantage of better directory layout and improve config. I've put together a very rough proposal if anyone has feedback.
from express-enrouten.
Aye. That seems like an awful lot of DI machinery and jargon to drag in, and it means that we're coupled to doing dependency injection our way, which just makes it unpleasant for people who have another opinion there.
from express-enrouten.
I see the intent, but something is rubbing me really wrong about it.
from express-enrouten.
Yep, re: DI. I was considering using an existing implementation by default and injecting the router itself that way, but I haven't yet found a "lightweight" module, hence the code I put together. If we go through with this I'd prefer to defer to an existing module should we go in whole hog, and use it to manage all dependencies, including router.
from express-enrouten.
I dunno. It feels a lot like a lot of conceptual overhead to use an otherwise simple module.
from express-enrouten.
I'm im not sure that simplicity and configurability are mutually exclusive. The request to inject arbitrary objects during initialization isn't the basic, simple use-case here. A smart default of always injecting the router will most certainly help.
from express-enrouten.
Indeed.
from express-enrouten.
regarding the single argument function, just because a function signature has a single argument doesn't mean the function cannot be called with additional arguments
from express-enrouten.
True, but I'm personally not willing to codifyvar myvar = arguments[1];
as a desired pattern. :)
from express-enrouten.
What about attaching the config as a property of the router?
from express-enrouten.
That's interesting. We already provide a facade there.
from express-enrouten.
Well attaching config
explicitly so will create a tight coupling between kraken-js and enrouten, something that I'm trying to avoid. The only way to avoid that would be to support something like an additionalProperties
config property that would be an object of arbitrary stuff which would get attached to the router instance.
With a design that supports multiple arguments the default case (just router) could possibly keep the current scanning mechanism, but when additional dependencies are configured to be injected it could switch into a more liberal scanning mode. That would preserve backward compat.
from express-enrouten.
the single argument could be an object but the user would need to be aware of when they have triggered DI in order to pull the router
argument apart
from express-enrouten.
+1 to adding additional params as a config
from express-enrouten.
Does someone want to put together a proposal?
from express-enrouten.
I don't have much time today and tomorrow. But if it's still dangling when I'm free I would like to take a crack at it.
from express-enrouten.
Related Issues (20)
- Route middleware passed onto other routes
- Project Status
- Router level middleware HOT 11
- How to get all original paths of registered routes HOT 1
- Creating routes for subdomains HOT 2
- multer don't work on middlware HOT 1
- Is this over-designed? HOT 3
- Files with no extension are being processed by the directory traversal HOT 2
- Not able to upgrade engine-munger(version 1.1.1) HOT 1
- Non-JS files being accidently required
- directory: too quiet on requiring bad controller files
- Option to possibly use a different router than Express's default Router
- silently failing to require a route HOT 1
- Named routes HOT 1
- can config muilt directores
- Allow to ignore glob path HOT 3
- Jest incompatibility HOT 3
- Route name query HOT 1
- Support path-to-regexp somehow?
- Nested routes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-enrouten.