當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。