You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
993 B
JavaScript
42 lines
993 B
JavaScript
#!/usr/bin/env node
|
|
//# vi: ft=javascript
|
|
|
|
var fs = require('fs');
|
|
|
|
var handlebars = require('handlebars');
|
|
var express = require('express');
|
|
|
|
var app = express();
|
|
var staticHandler = express['static'].bind(express);
|
|
|
|
app.use((function log() {
|
|
var text = '{{date}} {{req.method}} {{req.url}}';
|
|
var logTemplate = handlebars.compile(text);
|
|
|
|
return function (req, res, next) {
|
|
console.log(logTemplate({date: new Date().toISOString(), req: req}));
|
|
next();
|
|
};
|
|
}()));
|
|
|
|
app.get('/', function index(req, res) {
|
|
var indexFile = __dirname + '/../assets/index.html';
|
|
|
|
function compileServe(err, text) {
|
|
if (err) {
|
|
res.writeHead(500, {'Content-Type': 'text/plain'}, err);
|
|
return;
|
|
}
|
|
var tmpl = handlebars.compile(text);
|
|
res.send(tmpl());
|
|
}
|
|
|
|
fs.readFile(indexFile, {encoding: 'utf8'}, compileServe);
|
|
});
|
|
|
|
app.use('/data', staticHandler('data'));
|
|
app.use('/vendor', staticHandler('vendor'));
|
|
app.use('/static', staticHandler('static'));
|
|
|
|
app.listen(8000);
|