I've just started out with node and am using primarily as a simple script to serve static resources to various different domain requests. However, I want to move into using templating but am having trouble getting it to work with my vhost routing. For example:var express = require('express'); var app = express(); var vhost = require('vhost'); var path = require('path'); var exphbs = require('express-handlebars'); app.engine('handlebars', exphbs({defaultLayout: 'main'})); app.set('view engine', 'handlebars'); var firstdomain = express.Router(); app.use(vhost('firstdomain.com', firstdomain)); firstdomain.use(express.static(path.join(__dirname, 'firstdomain'))); var seconddomain = express.Router(); app.use(vhost('seconddomain.com', seconddomain)); seconddomain.use(express.static(path.join(__dirname, 'seconddomain'))); firstdomain.get('*', function(req, res) { res.status(404); res.render('404'); }) seconddomain.get('*', function(req, res) { res.status(404); res.render('404'); }) app.listen(8080); Now the problem here is that I can't connect the template engine to the routing instances individually (firstdomain.engine... or firstdomain.set('view engine', 'handlebars') both throw non-existent function errors). This means that I can't seem to set a different views/layouts directory depending on which domain is requesting the script in the event of a 404 error (and so giving them individual error pages for each domain) and both domains serve the error page from my /path/to/default/views directory rather than /path/to/default/firstdomain/views and /path/to/default/seconddomain/views dirs respectively.I know I'm probably missing something blindingly obvious here, can anyone help?
Submitted January 03, 2018 at 04:14PM by floodlitworld
No comments:
Post a Comment