-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathserver.js
32 lines (23 loc) · 905 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// usage
// node server.js
process.title = 'node-website-template';
// core module
var http = require('http');
// npm packages
var ErrorPage = require('error-page');
var Templar = require('templar');
var router = require('routes')();
var environment = process.env.NODE_ENV || 'development';
var config = require('./config/' + environment + '.js');
var templarOptions = { engine: config.engine, folder: config.templates };
Templar.loadFolder(config.templates);
router.addRoute('/*', require('./routes/static.js'));
router.addRoute('/', require('./routes/home.js'));
http.createServer(function (req, res) {
res.error = ErrorPage(req, res, {
404: 'not found!'
});
res.template = Templar(req, res, templarOptions);
router.match(req.url).fn(req, res, config);
}).listen(config.port);
console.log('Server Listening - http://localhost:' + config.port + '. ' + environment + ' environment');