I want to serve html files from a folder if they exist, otherwise fallback to the dynamic app.
currently I use something like:
You don't have to do anything special.
i'm assuming the WebContent folder is in the root.
And if all your static content are in the same base folder like you've shown, you don't have to specify it multiple times.
app.use(express.static(__dirname + '/WebContent'));
if you have a file called file.html in the WebContent folder you can now access it via the url i.e. localhost:4444/file.html
You are using a lot of boilerplate. It is easier using routes
. Here is an example:
var routes = require('./routes');
app.configure(function () {
...
app.use(express['static'](path.join(__dirname, '/../WebContent')));
app.use(app.router);
});
// Routes
app.get('/', routes.index);
routes/index.js:
exports.index = function (req, res) {
res.render('index');
};
Rendering your webapp root outside your project root is very strange. Feels like bad practice. Is this necessary?