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


TypeScript koa-session類代碼示例

本文整理匯總了TypeScript中koa-session的典型用法代碼示例。如果您正苦於以下問題:TypeScript koa-session類的具體用法?TypeScript koa-session怎麽用?TypeScript koa-session使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了koa-session類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: require

import * as session from 'koa-session';
import * as Koa from 'koa';
import RedisStore = require('koa2-session-redis');

const app = new Koa();

const CONFIG = {
    store: new RedisStore({
        host: '127.0.0.1',
        port: 6379,
        max_attempts: 0
    })
};

app.use(session(CONFIG, app));
開發者ID:AlexGalays,項目名稱:DefinitelyTyped,代碼行數:15,代碼來源:koa2-session-redis-tests.ts

示例2: Koa

import * as Koa from 'koa';
import * as session from 'koa-session';

import {ip, port} from '../config/server';
import renderApp from './render-app';

const app = new Koa();

app.use(session(app));

app.use(renderApp);

app.listen(port, () => {
  // eslint-disable-next-line no-console
  console.log(`[init] listening on ${ip}:${port}`);
});

export default app;
開發者ID:debchn,項目名稱:shopify-app,代碼行數:18,代碼來源:index.ts

示例3: next

// const debug = true
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'
開發者ID:zerolugithub,項目名稱:rap2-delos,代碼行數:31,代碼來源:app.ts

示例4: Koa

decode("123");

hash("abc");

const app = new Koa();

app.use(session({
    valid: (ctx, sess) => {
        const { session: s } = ctx;
        if (s) {
            s.sess = "validated";
            s.save();
            return true;
        }
        return false;
    },
    store: {
        get: async (key) => {
            return "abc";
        },
        set: (key, val) => {
            console.log(key, val);
        },
        destroy: (key) => {
            console.log(key);
        },
    },
}, app));

app.listen(3000);
開發者ID:DavidM77,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:koa-session-tests.ts

示例5: next

};

app.keys = ["some secret hurr"];

// 錯誤處理
app.use(async (ctx, next) => {
  try {
    await next();
  } catch (err) {
    errorHandler(ctx, next, err);
  }
});

app.use(bodyParse());

app.use(session(sessionConfig, app));

// app.use((ctx, next) => {
//   const userName = ctx.session.user || "";
// });

app.use(apiRouters.routes()).use(apiRouters.allowedMethods());

app.use((ctx, next) => {
  // 根據狀態碼拋出相應錯誤
  const statusCode = ctx.response.status;
  switch (statusCode) {
    case 404:
      throw new ResourceNotFoundError(ctx.request.method, ctx.request.url, "沒有找到您所需要的資源");
  }
});
開發者ID:IWSR,項目名稱:Blog_system,代碼行數:31,代碼來源:index.ts


注:本文中的koa-session類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。