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


TypeScript koa-logger.default方法代码示例

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


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

示例1: 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,代码来源:

示例2: 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

示例3: 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

示例4: 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

示例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.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。