• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript koa-logger类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了koa-logger类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: next

import * as Koa from 'koa'
import * as session from 'koa-session'
import * as logger from 'koa-logger'
import * as serve from 'koa-static'
import * as body from 'koa-body'
import * as cors from 'kcors'
import router from '../routes'
import config from '../config'

const app = new Koa()
let appAny: any = app
appAny.counter = { users: {}, mock: 0 }

app.keys = config.keys
app.use(session(config.session, app))
if (process.env.NODE_ENV === 'development') app.use(logger())
app.use(async(ctx, next) => {
  await next()
  if (ctx.path === '/favicon.ico') return
  ctx.session.views = (ctx.session.views || 0) + 1
  let app: any = ctx.app
  if (ctx.session.fullname) app.counter.users[ctx.session.fullname] = true
})
app.use(cors({
  credentials: true
}))
app.use(async(ctx, next) => {
  await next()
  if (typeof ctx.body === 'object' && ctx.body.data !== undefined) {
    ctx.type = 'json'
    // ctx.body.path = ctx.path
开发者ID:zerolugithub,项目名称:rap2-delos,代码行数:31,代码来源:app.ts


示例2: next

import * as logger from 'koa-logger'
import * as serve from 'koa-static'
import * as cors from 'kcors'
import * as bodyParser from 'koa-body'
import router from '../routes'
import config from '../config'

const app = new Koa()
let appAny: any = app
appAny.counter = { users: {}, mock: 0 }

app.keys = config.keys
app.use(session({
  store: redisStore(config.redis)
}))
if (process.env.NODE_ENV === 'development' && process.env.TEST_MODE !== 'true') app.use(logger())
app.use(async (ctx, next) => {

  ctx.set('Access-Control-Allow-Origin', '*');
  ctx.set('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS')
  ctx.set('Access-Control-Allow-Credentials', 'true')
  await next()
  if (ctx.path === '/favicon.ico') return
  ctx.session.views = (ctx.session.views || 0) + 1
  let app: any = ctx.app
  if (ctx.session.fullname) app.counter.users[ctx.session.fullname] = true
})
app.use(cors({
  credentials: true,
}))
app.use(async (ctx, next) => {
开发者ID:tonyjt,项目名称:rap2-delos,代码行数:31,代码来源:app.ts


示例3: Router

// framework like InversifyJS. There are plugins for express and koa (see also
// e.g. https://www.npmjs.com/package/inversify-koa-utils)

// Read more about routing at https://github.com/alexmingoia/koa-router
const router = new Router({prefix: '/api'});
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');
});
开发者ID:,项目名称:,代码行数:30,代码来源:


示例4: cpus

logger.info(`Starting application in ${APP.mode} mode.`);

// redis.get('test'); // just for test redis.

initOracle();

if (isMaster && APP.mode === 'production') {
    logger.info(`Master node ${process.pid} online!`);
    cpus().forEach(() => fork());
    on('online', (worker, code, signal) => logger.info(`Slave node ${worker.process.pid} online!`));
    on('exit', (worker, code, signal) => logger.info(`Slave node ${worker.process.pid} died!`));
    on('disconnect', worker => { logger.info(`Slave node ${worker.process.pid} disconnect!`); fork(); });
} else {
    try {
        const app = new Koa();
        app.use(Koalogger());

        app.use(Convert(require('koa-cors')(CORSConfig)));

        app.use(new AuthController().router.routes());
        app.use(new UserController().router.routes());

        // 冗余实现
        app.use(new NodeController().routes());
        app.use(new NodeCtrl().routes());
        app.use(new RoleCtrl().routes());
        app.use(new MenuCtrl().routes());
        app.use(new UserCtrl().routes());
        app.use(new CodeCtrl().routes());
        app.use(new FileCtrl().routes());
开发者ID:wangxin0709,项目名称:csc-scms-node-koa,代码行数:30,代码来源:app.ts


示例5: Koa

import * as serve from 'koa-static';
import * as cors from 'koa2-cors';

import * as path from 'path';

import rank from './routes/rank';
import news from './routes/news';
import analytics from './routes/analytics';
import summarize from './routes/summarize';
import { crawlJob } from './database/crawler';

const app = new Koa();
const port = process.env.PORT || 3000;
const dist = path.join(__dirname, '..', 'public');
const bpOption = { extendTypes: { json: ['application/x-javascript'] } };

app
  .use(koaLogger())
  .use(bodyParser(bpOption))
  .use(cors())
  .use(rank.routes())
  .use(analytics.routes())
  .use(news.routes())
  .use(summarize.routes())
  .use(serve(dist));

if (process.argv[2] === '--with-crawler') {
  crawlJob.start();
}
app.listen(port, () => logger.info(`Listening on PORT ${port}`));
开发者ID:endlessdev,项目名称:PortalRank,代码行数:30,代码来源:app.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript koa-mount类代码示例发布时间:2022-05-28
下一篇:
TypeScript koa-json-error类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap