Here is my project structure
public/
css/
images/
js/
routes/
index.js
users.js
views/
AdminView/
layouts/
layout.hbs
index.hbs
I am currently having a problem where I cannot load the right view on my Node Express app. Here is some of my code
users.js
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.send('respond');
});
router.get('/admin', function(req, res, next) {
res.render(__dirname + 'AdminView/pages/tables/job-posts', {title: 'Admin Page'});
});
module.exports = router;
app.js *a portion of it
// view engine setup
app.engine('hbs', hbs({extname: 'hbs', defaultLayout: 'layout' , layoutsDir: __dirname + '/views/layouts'}));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
// Render the main view static files
app.use(express.static(path.join(__dirname, 'public'))); // Render for /
app.use("/career", express.static(__dirname + '/public')); // Render for /carrer/
app.use("/career/form", express.static(__dirname + '/public')); // Render for /carrer/form
app.use("/users", express.static(__dirname + "/views/AdminView")); // Render for /users
// Problematic code below
app.use("/users/admin", express.static(__dirname + "/views/AdminView")); // Render for /users/admin
app.use('/', routes);
app.use('/users', users);
Here is the problem. When I am trying to access /users/admin, I do not know why it renders the index page on the AdminView folder full with the css, js and images, while it should be rendering the one I specified on the routing (AdminView/pages/tables/job-posts).
Though, if I comment the line that is problematic above, it loads the html file which i specified on the routing file, but does not render the static files.
Side note:
- I have 2 website, one is the main website, the other one is the admin page. All of the admin resources are on the views/AdminView folder
- Full app.js http://pastebin.com/YFAbcKRz
- Full users.js http://pastebin.com/TZrdFYA2
The file what I trying to load is on the picture below