Skip to content
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

jade templating with express.vhost #1277

Closed
bodokaiser opened this issue Aug 11, 2012 · 11 comments
Closed

jade templating with express.vhost #1277

bodokaiser opened this issue Aug 11, 2012 · 11 comments

Comments

@bodokaiser
Copy link

Hi,

I got following directory structure:

/
    /main - contains the main app
        /routes
        /public
        /app.js
    /security - contains security related stuff
        /routes
        /public
        /app.js
    /views
        /index.js
        /layout.js
    /app.js - node bootstrap

Because my content is completely client rendered I would like to share the views across the subdomains.

But I now noticed that when I define the view options in the main application file (/app.js):

app.set('views', __dirname + '/views');
app.set('view engine', 'jade');

instead of in the subapplication files (/main/app.js, /security/app.js)
I get follwoing error by calling "res.render('index');

Error: Cannot find module 'undefined'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at new View (/Users/bodo/Repositories/Node/node_modules/express/lib/view.js:42:49)
    at Function.app.render (/Users/bodo/Repositories/Node/node_modules/express/lib/application.js:486:12)
    at ServerResponse.res.render (/Users/bodo/Repositories/Node/node_modules/express/lib/response.js:677:7)
    at /Users/bodo/Repositories/Node/security/routes/index.js:5:12
    at callbacks (/Users/bodo/Repositories/Node/node_modules/express/lib/router/index.js:165:11)
    at param (/Users/bodo/Repositories/Node/node_modules/express/lib/router/index.js:139:11)

Could this be a bug?

@tj
Copy link
Member

tj commented Aug 11, 2012

so the res.render()s are in the ./main/ etc? and app.set()s in ./app.js? not sure I get it

@bodokaiser
Copy link
Author

@visionmedia yes, res.renders are in ./main and /security and app.sets() and the jade templates itself are in /app.js and /views.

this doesn't work. But if I put everying (options, renders, views) in one dir (/main for example) it works

@tj
Copy link
Member

tj commented Aug 11, 2012

hmm yeah the subapps should be inheriting those settings

@bodokaiser
Copy link
Author

So we actually have a bug?

@tj
Copy link
Member

tj commented Aug 11, 2012

possibly yeah, I'll see if I can reproduce this in a bit

@tj
Copy link
Member

tj commented Sep 27, 2012

things have been refactored quite a bit, closing unless it's still an issue

@tj tj closed this as completed Sep 27, 2012
@geoah
Copy link

geoah commented Dec 24, 2012

Yeap, this is still an issue with 3.0.5
Anyone got any idea how to hack/fix it? :)

@geoah
Copy link

geoah commented Dec 25, 2012

Ok I've pinpointed the problem but don't have enough knowledge of the internals of express to fix it.
I'll try fix it but in case someone has any ideas...

application.js line 483

defaultEngine: this.get('view engine'),

Returns undefined in what @bodokaiser has presented earlier.
This will cause view.js line 43

this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express);

To try and require undefined since ext is ".undefined".

An easy hack is to use

app.set('view engine', 'jade');

Inside each vhost.

@bodokaiser
Copy link
Author

@visionmedia @geoah

The problem is actually just a bigger typo, I think.

view = new View(name, {
      defaultEngine: this.get('view engine'),
      root: this.get('views'),
      engines: engines
    });

this in the object hash does not refer to app anymore. It refers to the object hash.

Can somebody try to rename this to app then it could work. I currently got no use case to test it out.

Regards,
Bodo

@geoah
Copy link

geoah commented Dec 25, 2012

After some digging around I think that it has something to do with how we use vhosts and how settings are being set.
I created a simple test case. https://gist.github.com/4372713

From what I understand settings are local to the app instance that we have at the moment. Is that correct?
In app.set there is a reference to .parent - what is this?

@geoah
Copy link

geoah commented Dec 28, 2012

By the way can someone re-open this ticket? It doesn't seem right to open a new one for the same reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants