-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
39 lines (32 loc) · 1.01 KB
/
index.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
33
34
35
36
37
38
39
'use strict';
var path = require('path');
var http = require('http');
var express = require('express');
var hbs = require('express-hbs');
var pkg = require('./package.json');
var app = express();
var port = process.env.PORT || 61913;
hbs.registerHelper('stringify', function (data) {
return JSON.stringify(data, null, 2);
});
// use handlebars using .html as the extension for syntax highlighting
app.engine('html', hbs.express3({
extname: '.html',
defaultLayout: path.resolve(__dirname + '/views/layout.html'),
}));
app.set('views', path.resolve(__dirname + '/views'));
app.set('view engine', 'html');
app.all('/foo', function(req, res) {
res.send({ value: 'bar' });
});
app.all('/', function(req, res) {
res.render('hello');
});
app.all('/echo/:echo', function(req, res) {
res.render('echo', {
echo: req.params.echo
});
});
var server = http.createServer(app).listen(port, function () {
console.log(pkg.name + ' v' + pkg.version + ' is up and running on port http://localhost:' + server.address().port);
});