本文整理汇总了TypeScript中koa-views.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript koa-views.default方法的具体用法?TypeScript koa-views.default怎么用?TypeScript koa-views.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类koa-views
的用法示例。
在下文中一共展示了koa-views.default方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Koa
import * as Koa from 'koa'
import * as views from 'koa-views'
import * as bodyParser from 'koa-bodyparser'
import * as http from 'http'
import * as path from 'path'
import router from './router'
import { connectDB } from './db'
const app = new Koa()
app.use(views(path.join(__dirname, '')))
app.use(bodyParser())
console.log('connecting database')
connectDB().then(() => {
console.log('database connected')
app.use(router.routes())
http.createServer(app.callback()).listen(4000, () => {
console.log(`http server listening on port: 4000`)
})
})
示例2: Koa
router.get('/people', getAllPeople);
router.get('/todos', getAllTodo);
router.get('/todos/:id', getTodo);
router.post('/todos', addTodo);
router.patch('/todos/:id', patchTodo);
router.delete('/todos/:id', deleteTodo);
// Read more about koa at http://koajs.com/
const app = new Koa();
app.use(cors());
app.use(logger());
app.use(bodyParser());
app.use(router.routes());
// Read more about koa views at https://github.com/queckezz/koa-views
// Read more about Nunjucks at https://mozilla.github.io/nunjucks/
const viewPath = path.join(__dirname, 'views');
app.use(views(viewPath, {
map: {html: 'nunjucks'},
options: {loader: new FileSystemLoader(viewPath)}
}));
app.use(async (ctx, next) => {
// If nothing else was found, render index (assumption: single-page app)
await ctx.render('index');
});
const port: (number|string) = process.env.PORT || 8080;
app.listen(port, () => {
console.log(`Server is listening on port ${port}...`);
});
示例3: Error
views(`${__dirname}/views`, {
extension: "hbs",
map: {
hbs: "handlebars",
},
options: {
partials: {
"admin-menu": "./partials/admin-menu",
card: "./partials/card",
footer: "./partials/footer",
header: "./partials/header",
"html-foot": "./partials/html-foot",
"html-head": "./partials/html-head",
sidebar: "./partials/sidebar",
},
helpers: {
eq: function fna(this: any, lvalue: any, rvalue: any, options: any) {
if (arguments.length < 3) {
throw new Error("Handlebars Helper equal needs 2 parameters");
}
if (lvalue !== rvalue) {
return options.inverse(this);
} else {
return options.fn(this);
}
},
neq: function fnb(this: any, lvalue: any, rvalue: any, options: any) {
if (arguments.length < 3) {
throw new Error("Handlebars Helper equal needs 2 parameters");
}
if (lvalue !== rvalue) {
return options.fn(this);
} else {
return options.inverse(this);
}
},
},
},
})
示例4: Date
// app.use(convert(bunyanLogger(logger, {
// level: 'info',
// timeLimit: 250
// })));
app.use(koaSession({ maxAge: 3000000, expires: new Date(Date.now() + 3000000) }));
app.use(mongooseMiddleware);
app.use(favicon(Path.join(__dirname, '..', 'favicon.ico')));
// 添加ejs视图解析器
app.use(views(Path.resolve(__dirname, '../', 'views'), {
map: {
html: 'ejs',
},
}));
// 添加静态资源服务中间件
app.use(serve(Config.static.directory));
// 添加assets管道
app.use(pipeLine({
manifest: Path.join(__dirname, '../', 'manifest.json'),
prepend: '',
}));
// 添加各种中间件
示例5: Koa
import * as Koa from "koa";
import * as views from "koa-views";
const app = new Koa();
app.use(views('/views', {
map: {
html: 'underscore'
},
extension: '.html',
engineSource: {},
options: {}
}));
app.use((ctx: Koa.Context) => {
ctx.render('user', {
user: 'John'
}).then(() => console.log('done render call'));
});
示例6: next
import { fa } from '../../misc/fa';
import config from '../../config';
import Note, { pack as packNote } from '../../models/note';
import getNoteSummary from '../../misc/get-note-summary';
const consts = require('../../const.json');
const client = `${__dirname}/../../client/`;
// Init app
const app = new Koa();
// Init renderer
app.use(views(__dirname + '/views', {
extension: 'pug',
options: {
config,
themeColor: consts.themeColor,
facss: fa.dom.css()
}
}));
// Serve favicon
app.use(favicon(`${client}/assets/favicon.ico`));
// Common request handler
app.use(async (ctx, next) => {
// IFrameの中に入れられないようにする
ctx.set('X-Frame-Options', 'DENY');
await next();
});
// Init router