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


TypeScript koa-router.use函数代码示例

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


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

示例1: return

 return (target: any, key?: string | symbol, descriptor?: any): void => {
   // Decorator applied to Class (for Constructor injection).
   if (typeof target === 'function' && key === undefined && descriptor === undefined) {
     if (!target.prototype.router) {
       target.prototype.router = new Router();
     }
     if (middleware.length > 0) {
       target.prototype.router.use(...middleware);
     }
     router.use(path, target.prototype.router.routes(), target.prototype.router.allowedMethods());
     return;
   } else if (typeof target === 'object') {
     if (!target.router) {
       target.router = new Router();
     }
     const handleReturnMiddleware = async function (ctx: Context) {
       await formatResponse(descriptor, ctx);
     };
     // Decorator applied to member (method or property).
     switch (method) {
       case HttpMethod.HEAD:
         target.router.head(path, ...middleware, handleReturnMiddleware);
         break;
       case HttpMethod.OPTIONS:
         target.router.options(path, ...middleware, handleReturnMiddleware);
         break;
       case HttpMethod.GET:
         target.router.get(path, ...middleware, handleReturnMiddleware);
         break;
       case HttpMethod.PUT:
         target.router.put(path, ...middleware, handleReturnMiddleware);
         break;
       case HttpMethod.PATCH:
         target.router.patch(path, ...middleware, handleReturnMiddleware);
         break;
       case HttpMethod.POST:
         target.router.post(path, ...middleware, handleReturnMiddleware);
         break;
       case HttpMethod.DELETE:
         target.router.del(path, ...middleware, handleReturnMiddleware);
         break;
       default:
         target.router.all(path, ...middleware, handleReturnMiddleware);
         break;
     }
   }
 };
开发者ID:bibim18,项目名称:backtrello,代码行数:47,代码来源:index.ts

示例2: next

  logger.accessInfo({
    message: "Log out",
    context: ctx
  });
});

koa.use(async (ctx, next) => {
  if (ctx.request.type === "application/octet-stream")
    ctx.disableBodyParser = true;

  return next();
});

koa.use(koaBodyParser());
router.use("/api", api.routes(), api.allowedMethods());

router.get("/", async ctx => {
  let permissionSets = [];
  if (ctx.state.user && ctx.state.user.roles)
    permissionSets = getPermissionSets(ctx);

  ctx.body = `
  <html>
    <head>
      <title>GenieACS</title>
      <link rel="shortcut icon" type="image/png" href="favicon.png" />
      <link rel="stylesheet" href="app.css">
    </head>
    <body>
      <script>
开发者ID:zaidka,项目名称:genieacs,代码行数:30,代码来源:ui.ts

示例3: Router

import * as Router from "koa-router";
import loginRouter from "./login";
import userRouter from "./user";

const routers = new Router();

routers.get("/", (ctx, next) => {
  ctx.body = "hello world";
});

routers.use("/login", loginRouter.routes(), loginRouter.allowedMethods());
routers.use("/user", userRouter.routes(), userRouter.allowedMethods());

export const apiRouters = routers;
开发者ID:IWSR,项目名称:Blog_system,代码行数:14,代码来源:index.ts

示例4: KoaRouter

import idTokenAuth from '../middlewares/idTokenAuth';
import verifyXapiVersion from '../middlewares/verifyXapiVersion';
import verifyAppApiKey from '../middlewares/verifyAppApiKey';
import about from './handlers/about';
import healthz from './handlers/healthz';
import statements from './handlers/statements';
import results from './handlers/results';
import entityStructure from './handlers/entityStructure';

const router = new KoaRouter();

router.get('/xAPI/about', about);
router.get('/healthz', healthz);

router.post('/entity/structure', verifyAppApiKey, entityStructure.put);
router.get('/entity/structure', auth, entityStructure.get);

router.use(verifyXapiVersion);
router.post('/xAPI/statements', statements.post);

router.post('/xAPI/results/archive/:attemptId', idTokenAuth, results.archive);
router.post('/xAPI/results/unarchive/:attemptId', idTokenAuth, results.unarchive);

router.use(auth);
router.get('/xAPI/statements', statements.get);
router.get('/xAPI/results', results.get);
router.get('/xAPI/results/csv', results.getCsv);
router.get('/xAPI/results/raw', results.getRaw);

export default router;
开发者ID:easygenerator,项目名称:lrs,代码行数:30,代码来源:index.ts

示例5: multer

	// リクエストが multipart/form-data でない限りはJSONだと見なす
	detectJSON: ctx => !ctx.is('multipart/form-data')
}));

// Init multer instance
const upload = multer({
	storage: multer.diskStorage({})
});

// Init router
const router = new Router();

/**
 * Register endpoint handlers
 */
endpoints.forEach(endpoint => endpoint.meta.requireFile
	? router.post(`/${endpoint.name}`, upload.single('file'), handler.bind(null, endpoint))
	: router.post(`/${endpoint.name}`, handler.bind(null, endpoint))
);

router.post('/signup', require('./private/signup').default);
router.post('/signin', require('./private/signin').default);

router.use(require('./service/github').routes());
router.use(require('./service/twitter').routes());

// Register router
app.use(router.routes());

module.exports = app;
开发者ID:ha-dai,项目名称:Misskey,代码行数:30,代码来源:index.ts

示例6: Router

import { ensureAuthenticated } from './authUtils';
import * as Router from 'koa-router';
import * as authController from './auth.controller';
import * as meController from './me.controller';
import * as github from './github';
import * as google from './google';
import * as facebook from './facebook';
import * as linkedin from './linkedin';
import * as live from './live';
import * as twitter from './twitter';

const router = new Router();

// routes
router.post('/login', authController.login);
router.post('/signup', authController.signup);
router.post('/github', github.authenticate);
router.post('/google', google.authenticate);
router.post('/facebook', facebook.authenticate);
router.post('/linkedin', linkedin.authenticate);
router.post('/live', live.authenticate);
router.post('/twitter', twitter.authenticate);

// auth only applied for following routes, not the routes above
router.use(['/me', '/unlink'], ensureAuthenticated);
router.get('/me', meController.getMe );
router.put('/me', meController.updateMe );
router.get('/unlink/:provider', meController.unlink);

export default router.routes();
开发者ID:ghiscoding,项目名称:Realtime-TODO-Aurelia-RethinkDB,代码行数:30,代码来源:index.ts

示例7: next

  .post('/:id/delete', hearthstoneMatchController.remove);

blog.get('/', blogController.list)
  .post('/', blogController.create)
  .post('/upload', upload.single('file'), blogController.upload)
  .get('/:url', blogController.find)
  .post('/:url', blogController.update)
  .post('/:url/delete', blogController.remove)
  .post('/:url/publish', blogController.publish)
  .post('/:url/unpublish', blogController.unpublish);

api.use(async (ctx, next) => {
  let auth = ctx.headers.auth;

  if (auth == Keys.api[ctx.method]) {
    await next();
  } else {
    ctx.status = 401;
    ctx.body = 'Unauthorized';
  }
})

api.get('/counts', countController.list)
  .post('/images', upload.single('file'), imageController.create)
  .use('/games', game.routes(), game.allowedMethods())
  .use('/gourmets', gourmet.routes(), gourmet.allowedMethods())
  .use('/hearthstone-seasons', hearthstoneSeason.routes(), hearthstoneSeason.allowedMethods())
  .use('/hearthstone-decks', hearthstoneDeck.routes(), hearthstoneDeck.allowedMethods())
  .use('/hearthstone-matches', hearthstoneMatch.routes(), hearthstoneMatch.allowedMethods())
  .get('/hearthstone-cards', hearthstoneCardController.list)
  .post('/game-trophy', trophyController.scrap)
  .use('/blogs', blog.routes(), blog.allowedMethods());
开发者ID:Bill0106,项目名称:MySite,代码行数:32,代码来源:routes.ts

示例8: Router

import * as Router from 'koa-router';
import AuthRouter from './auth';
import CustomerRouter from './customers';
import TodoRouter from './todos';

const apiRouter = new Router();
apiRouter.use('/auth', AuthRouter);
apiRouter.use('/api/customers', CustomerRouter);
apiRouter.use('/api/todos', TodoRouter);

export const routes = apiRouter.routes();
开发者ID:ghiscoding,项目名称:Realtime-TODO-Aurelia-RethinkDB,代码行数:11,代码来源:routes.ts

示例9: next

// 6months (15552000sec)
if (config.url.startsWith('https')) {
	app.use(async (ctx, next) => {
		ctx.set('strict-transport-security', 'max-age=15552000; preload');
		await next();
	});
}

app.use(mount('/api', require('./api')));
app.use(mount('/files', require('./file')));

// Init router
const router = new Router();

// Routing
router.use(activityPub.routes());
router.use(webFinger.routes());

// Register router
app.use(router.routes());

app.use(mount(require('./web')));

function createServer() {
	if (config.https) {
		const certs: any = {};
		Object.keys(config.https).forEach(k => {
			certs[k] = fs.readFileSync(config.https[k]);
		});
		certs['allowHTTP1'] = true;
		return http2.createSecureServer(certs, app.callback());
开发者ID:ha-dai,项目名称:Misskey,代码行数:31,代码来源:index.ts

示例10: Router

import * as Router from 'koa-router';
import profileRouter from './profile';
import answerRouter from './answer';
import checkAccountRouter from './checkAccount';
import loginRouter from './login';
import registerRouter from './register';
import questionRouter from './question';
import tagRouter from './tag';
import signUpRouter from './signUp';


const router = new Router();
router.use('/profile', profileRouter.routes());
router.use('/login', loginRouter.routes());
router.use('/register', registerRouter.routes());
router.use('/checkAccount', checkAccountRouter.routes());
router.use('/question', questionRouter.routes());
router.use('/answer', answerRouter.routes());
router.use('/tag', tagRouter.routes());
router.use('/signUp', signUpRouter.routes());

export default router;
开发者ID:DavidOnGitHub,项目名称:questionApp_backend,代码行数:22,代码来源:api.ts


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