当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript koa-views类代码示例

本文整理汇总了TypeScript中koa-views的典型用法代码示例。如果您正苦于以下问题:TypeScript koa-views类的具体用法?TypeScript koa-views怎么用?TypeScript koa-views使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了koa-views类的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`)
    })
})
开发者ID:YimYijet,项目名称:WebTest,代码行数:24,代码来源:index.ts

示例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}...`);
});
开发者ID:,项目名称:,代码行数:30,代码来源:

示例3: 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'));
});
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:19,代码来源:koa-views-tests.ts

示例4: 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);
         }
       },
     },
   },
 })
开发者ID:coderfox,项目名称:Another-SS-Panel,代码行数:39,代码来源:server.ts

示例5: 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: '',
}));

// 添加各种中间件
开发者ID:Kpyu,项目名称:AntCMS,代码行数:31,代码来源:index.ts

示例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
开发者ID:ha-dai,项目名称:Misskey,代码行数:32,代码来源:index.ts


注:本文中的koa-views类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。