當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript koa-logger類代碼示例

本文整理匯總了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;未經允許,請勿轉載。