Configure Express and add public files

This commit is contained in:
Rowan Manning
2013-09-16 09:05:00 +01:00
parent f951f7c734
commit 8d4f79128d
3 changed files with 26 additions and 1 deletions

17
app.js
View File

@@ -18,6 +18,13 @@ function initApp (config, callback) {
app.server = http.createServer(app.express); app.server = http.createServer(app.express);
app.webservice = createClient(config.webservice); app.webservice = createClient(config.webservice);
// Express config
app.express.disable('x-powered-by');
app.express.use(express.static(__dirname + '/public', {
maxAge: (process.env.NODE_ENV === 'production' ? 604800 : 0)
}));
app.express.use(express.compress());
// View engine // View engine
app.express.set('views', __dirname + '/view'); app.express.set('views', __dirname + '/view');
app.express.engine('html', hbs.express3({ app.express.engine('html', hbs.express3({
@@ -29,6 +36,16 @@ function initApp (config, callback) {
})); }));
app.express.set('view engine', 'html'); app.express.set('view engine', 'html');
// Populate view locals
app.express.locals({
lang: 'en',
year: (new Date()).getFullYear()
});
app.express.use(function (req, res, next) {
res.locals.host = req.host;
next();
});
// Load routes // Load routes
require('./route/index')(app); require('./route/index')(app);
require('./route/new')(app); require('./route/new')(app);

6
public/example.css Normal file
View File

@@ -0,0 +1,6 @@
/* Just an example CSS file. Delete it when you add actual CSS */
body {
font-family: sans-serif;
}

View File

@@ -1,11 +1,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="{{lang}}">
<head> <head>
<meta charset="utf-8"/> <meta charset="utf-8"/>
<title>{{block "title"}}</title> <title>{{block "title"}}</title>
<meta name="description" content="{{block "description"}}"/> <meta name="description" content="{{block "description"}}"/>
<link rel="stylesheet" href="/example.css"/>
</head> </head>
<body> <body>