-
-
Save emerleite/862782 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// path/to/module/debug.js | |
var express = require('express'); | |
exports.diagnostics = function() { | |
var app1 = express.createServer(); | |
app1.configure(function() { | |
this.set('view engine', 'ejs'); | |
this.set('views', __dirname + '/views/app1'); | |
this.set('view options', { layout: false, open: '{%', close: '%}' }); | |
}); | |
app1.mounted(function(host) { | |
host.dynamicHelpers({ | |
app1inc: function(req, res) { | |
return function(ctx) { | |
// XXX res.app is app1, so this fails... | |
// the intention is that the app we're mounted in | |
// should get the content from our bundled include | |
return res.partial('_include.ejs', { object: ctx, as: 'foo' }); | |
} | |
} | |
}); | |
}); | |
app1.get('/', function(req, res) { res.render('index.ejs'); }); | |
return app1; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- path/to/module/views/index.ejs --> | |
<!-- served at: http://localhost:3000/debug/index.ejs --> | |
<div>packaged app index</div> | |
<!-- this partial works fine: --> | |
<%- partial('include.ejs', { object: { test: 'hosted' }, as: 'foo' }) %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- path/to/module/views/partials/include.ejs --> | |
<div>packed app include: foo.test is {%= foo.test %}</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./apps.js: main app | |
var express = require('express'); | |
var debug = require('debug'); | |
var app2 = express.createServer(); | |
app2.configure(function() { | |
this.set('view engine', 'ejs'); | |
this.set('views', __dirname + '/views/app2'); | |
this.set('view options', { layout: false }); | |
}); | |
// uses packaged 'debug' app | |
app2.use('/debug', debug.diagnostics()); | |
app2.get('/', function(req, res) { res.render('index.ejs'); }); | |
if (! module.parent) { | |
app2.listen(3000); | |
console.log("Express server listening on port %d", app2.address().port); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ./views/index.ejs --> | |
<h1>App 2</h1> | |
<p><%- app1inc({ test: 'app2' }) %></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment