I am currently working on a web application using express.js. I want to have an interface and backend. The interface should display some content from the database, in the backend I want to create this content (similar to cms).
I started with this folder structure:
app/ βββ frontend/ β βββ public //Javascript, css & images only for frontend β βββ views //Frontend jade templates β βββ client.js β βββ backend/ β βββ public //Only backend css & stuff β βββ views //Backend templates β βββ core.js β βββ server.js //Starts the whole application
.Js server
var express = require('express'); var app = express(); var config = require('../app/config.json')[app.get('env')]; var backend = require('./backend/core'); var frontend = require('./frontend/client'); app.use(backend); app.use(frontend); app.set('port', config.port || 3000); var server = app.listen(app.get('port'), function() { console.log('Server listening on port ' + app.get('port') + ' in ' + app.get('env') + ' mode'); });
client.js
var express = require('express'); var app = express(); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.static(__dirname + '/public')); app.get('/', function(req, res) { res.render('layout', {title: 'Frontpage'}); }); app.get('/about', function(req, res) { res.render('layout', {title: 'About us'}); }); module.exports = app;
and core.js
var express = require('express'); var app = express(); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.static(__dirname + '/public')); app.get('/login', function(req, res) { res.render('layout', {title: 'Login'}); }); app.get('/login/dashboard', function(req, res) { res.render('layout', {title: 'Dashboard'}); }); module.exports = app;
express.js loads the correct templates, but not the correct stylesheet. For each, a backend style sheet is loaded.
localhost:3000/about
should load the stylesheet in
frontend/public/css/
and
localhost:3000/login
should load css in
backend/public/css/
How can i fix this?