本文整理汇总了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
示例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) => {
示例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');
});
示例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());
示例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}`));