-
Notifications
You must be signed in to change notification settings - Fork 146
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
Allow multiple instances with different setup #4
base: master
Are you sure you want to change the base?
Conversation
Instead of changing the settings at the module level, we allow the user to create a new instance of `partials` for each Express instance. This avoid issues with conflicting settings when multiple Express engines are running concurrently. In that case the usage would then be: var express_partials = require('express-partials'); /* express1 uses jade */ express1.set('view engine','jade'); partials1 = express_partials(); partials1.register('html','jade'); express1.use(partials1); /* express2 uses ejs */ express2.set('view engine','ejs'); partials2 = express_partials(); partials2.register('html','ejs'); express2.use(partials1); Without this patch, the latest `register('html',...')` called would override the options for both.
Right, it's probably a good idea to not make those extensions "global". But, hmm...maybe there is a way we can use express' own register for this instead? That way it would be nicely contained on an app-basis and we don't have to duplicate more code than necessary (i.e. the lookup code for Just an idea... |
That'd be Looking more closely at the code for express-partials, actually I see in the comments:
This makes it sound like the So yes, if we rewrite |
Rewriting So if we want to make it work that way we'll have to look into e.g. node-fibers. FWIW my (untested) attempt is in my async-partial branch -- I probably got the loop as async pattern wrong anyhow. |
Yes, one of the biggest changes since express 2.x (i think) is that the views are expected to be async. Even if they're not, in which they're wrapped in a async-like function. And writing a partial that takes async is not impossible (you're half-way there it looks like) but right now most of the template engines seem sync anyway which I guess is why it hasn't been "solved" yet. But what I was thinking about was that a lot of that registering-of-extensions seems to be duplicated and that it must be a way to do this better. Like using Appreciate your input though! |
[sorry for the late followup, was out for a while]
That's a more generic discussion than the original topic of this issue, though. I was just trying to make sure the changes I proposed earlier would work if multiple concurrent Express instances were used. |
Waiting on publicclass/express-partials#4 to get integrated.
The implementation I proposed earlier doesn't deal well with different setup for views and partials using multiple Express processes in parallel.
Here's a simplified example:
Previously, the last
register('html',...')
called would override the options for both, breaking the other server.Notes:
index.js
, to keep the patch as simple as possible; basically all the module-level functions become instance-level functions;