mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 08:17:05 +00:00
27 lines
560 B
TypeScript
27 lines
560 B
TypeScript
import * as Koa from 'koa';
|
|
import hbs = require("koa-hbs");
|
|
import * as Path from 'path';
|
|
|
|
const app = new Koa();
|
|
|
|
hbs.registerHelper('link', (text: string, url: string) => {
|
|
text = hbs.Utils.escapeExpression(text);
|
|
url = hbs.Utils.escapeExpression(url);
|
|
|
|
let result = `<a href="${url}">${text}</a>`;
|
|
|
|
return new hbs.SafeString(result);
|
|
});
|
|
|
|
app.use(hbs.middleware({
|
|
viewPath: Path.join(__dirname, './views')
|
|
}));
|
|
|
|
app.use(async (ctx, next) => {
|
|
await ctx.render('index', {
|
|
title: 'Hello World!'
|
|
});
|
|
});
|
|
|
|
app.listen(3000);
|