Created
June 19, 2015 18:57
-
-
Save wholroyd/123086c2fe260240455a to your computer and use it in GitHub Desktop.
Nested Express apps. How it should be.
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
// ### The Root application | |
// ./index.js <- lives here | |
// ./views/index.hbs <- the view | |
// ./catsApp <- child app | |
var express = require('express'); | |
var app = express(); | |
var exphbs = require('express-handlebars'); | |
app.engine('hbs', exphbs({defaultLayout: 'single', extname: '.hbs'})); | |
app.set('view engine', 'hbs'); | |
app.get('/', function(req, res) { | |
res.render('index'); | |
}) | |
// This should be it's own instance, or have it's own locality of certain configuration options | |
// It should be able to have it's own view engine and be able to find views relative to it's root directory | |
app.use('/cats', require('catsApp')); | |
app.listen(3000); | |
// ### The Child Application | |
// ./catsApp/index.js <- lives here | |
// ./catsApp/views/index.jade <-- the view | |
var express = require('express'); | |
var catsApp = express(); | |
catsApp.set('view engine', 'jade'); | |
catsApp.get('/', function(req, res) { | |
res.render('index'); | |
}) | |
modules.export = catsApp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment