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


TypeScript koa-router.put函數代碼示例

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


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

示例1: constructor

	constructor() {
		const api = new GameApi();
		this.router = api.apiRouter();

		this.router.get('/v1/games',       api.list.bind(api));
		this.router.head('/v1/games/:id',  api.head.bind(api));
		this.router.get('/v1/games/:id',   api.view.bind(api));
		this.router.patch('/v1/games/:id',  api.auth(api.update.bind(api), 'games', 'update-own', [ Scope.ALL ]));
		this.router.post('/v1/games',       api.auth(api.create.bind(api), 'games', 'add-og', [ Scope.ALL ]));
		this.router.delete('/v1/games/:id', api.auth(api.del.bind(api), 'games', 'delete', [ Scope.ALL ]));

		const ratingApi = new RatingApi();
		this.router.post('/v1/games/:id/rating', api.auth(ratingApi.createForGame.bind(ratingApi), 'games', 'rate', [ Scope.ALL, Scope.COMMUNITY ]));
		this.router.put('/v1/games/:id/rating',  api.auth(ratingApi.updateForGame.bind(ratingApi), 'games', 'rate', [ Scope.ALL, Scope.COMMUNITY ]));
		this.router.get('/v1/games/:id/rating',  api.auth(ratingApi.getForGame.bind(ratingApi), 'games', 'rate', [ Scope.ALL, Scope.COMMUNITY ]));
		this.router.delete('/v1/games/:id/rating',  api.auth(ratingApi.deleteForGame.bind(ratingApi), 'games', 'rate', [ Scope.ALL, Scope.COMMUNITY ]));

		const starsApi = new StarApi();
		this.router.post('/v1/games/:id/star',   api.auth(starsApi.star('game').bind(starsApi), 'games', 'star', [ Scope.ALL, Scope.COMMUNITY ]));
		this.router.delete('/v1/games/:id/star', api.auth(starsApi.unstar('game').bind(starsApi), 'games', 'star', [ Scope.ALL, Scope.COMMUNITY ]));
		this.router.get('/v1/games/:id/star',    api.auth(starsApi.get('game').bind(starsApi), 'games', 'star', [ Scope.ALL, Scope.COMMUNITY ]));

		const backglassApi = new BackglassApi();
		this.router.post('/v1/games/:gameId/backglasses', api.auth(backglassApi.create.bind(backglassApi), 'backglasses', 'add', [ Scope.ALL, Scope.CREATE ]));
		this.router.get('/v1/games/:gameId/backglasses', backglassApi.list.bind(backglassApi));

		const mediumApi = new MediumApi();
		this.router.get('/v1/games/:gameId/media', mediumApi.list.bind(mediumApi));

		const eventsApi = new LogEventApi();
		this.router.get('/v1/games/:id/events', eventsApi.list({ byGame: true }).bind(eventsApi));
		this.router.get('/v1/games/:id/release-name', api.auth(api.releaseName.bind(api), 'releases', 'add', [ Scope.ALL, Scope.CREATE ]));
	}
開發者ID:freezy,項目名稱:node-vpdb,代碼行數:33,代碼來源:game.api.router.ts

示例2: buildRouter

    private buildRouter() {
        if (!this._built) {
            for (let [pathInfo, routeInfo] of routeManager.routeMap) {
                let prefix: string = routeManager.getRoutePrefix(routeInfo.constructor);
                let path: string = pathInfo.path;
                if (!path.startsWith("/")) {
                    path = prefix + path;
                }

                let route: Router.IMiddleware = this.wrapAction(routeInfo.constructor, routeInfo.function);
                switch (pathInfo.method) {
                    case "GET": this._router.get(path, route); break;
                    case "POST": this._router.post(path, route); break;
                    case "PUT": this._router.put(path, route); break;
                    case "DELETE": this._router.delete(path, route); break;
                    case "OPTIONS": this._router.options(path, route); break;
                    case "ALL": this._router.all(path, route); break;
                    default: {
                        try {
                            this._router[pathInfo.method.toLowerCase()](path, route); break;
                        } catch (error) {
                            //eat the undefined error;
                        }
                    }
                }
            }
            this._built = true;
        }
    }
開發者ID:Norgerman,項目名稱:Koa-ts,代碼行數:29,代碼來源:RouterBuilder.ts

示例3: constructor

	constructor() {
		const api = new UserApi();
		this.router = api.apiRouter();

		this.router.post('/v1/users',   api.create.bind(api));
		this.router.put('/v1/users',     api.auth(api.createOrUpdate.bind(api), '', '', [ Scope.SERVICE ]));
		this.router.get('/v1/users',     api.auth(api.list.bind(api), 'users', 'search', [ Scope.ALL ]));
		this.router.get('/v1/users/:id', api.auth(api.view.bind(api), 'users', 'view', [ Scope.ALL ]));
		this.router.put('/v1/users/:id', api.auth(api.update.bind(api), 'users', 'update', [ Scope.ALL ]));
		this.router.del('/v1/users/:id', api.auth(api.del.bind(api), 'users', 'delete', [ Scope.ALL ]));
		this.router.post('/v1/users/:id/send-confirmation', api.auth(api.sendConfirmationMail.bind(api), 'users', 'send-confirmation', [ Scope.ALL ]));

		const starApi = new StarApi();
		this.router.post('/v1/users/:id/star',   api.auth(starApi.star('user').bind(starApi), 'users', 'star', [ Scope.ALL, Scope.COMMUNITY ]));
		this.router.del('/v1/users/:id/star', api.auth(starApi.unstar('user').bind(starApi), 'users', 'star', [ Scope.ALL, Scope.COMMUNITY ]));
		this.router.get('/v1/users/:id/star',    api.auth(starApi.get('user').bind(starApi), 'users', 'star', [ Scope.ALL, Scope.COMMUNITY ]));

		const eventApi = new LogEventApi();
		this.router.get('/v1/users/:id/events',            eventApi.list({ byActor: true }).bind(eventApi));
	}
開發者ID:freezy,項目名稱:node-vpdb,代碼行數:20,代碼來源:user.api.router.ts

示例4: async

    router.put(`/${resource}/:id`, async (ctx, next) => {
      const id = ctx.params.id;

      const log = {
        message: `Put ${resource}`,
        context: ctx,
        id: id
      };

      const authorizer = ctx.state.authorizer;
      if (!authorizer.hasAccess(resource, 3)) {
        logUnauthorizedWarning(log);
        return void next();
      }

      const obj = ctx.request.body;

      const validate = authorizer.getValidator(resource, obj);
      if (!validate("put")) {
        logUnauthorizedWarning(log);
        return void (ctx.status = 403);
      }

      try {
        await apiFunctions.putResource(resource, id, obj);
      } catch (err) {
        log.message += " failed";
        logger.accessWarn(log);
        ctx.body = err;
        return void (ctx.status = 400);
      }

      logger.accessInfo(log);

      ctx.body = "";
    });
開發者ID:zaidka,項目名稱:genieacs,代碼行數:36,代碼來源:api.ts

示例5: async

});

/**
 * @api {PUT} /:token Create or update link
 * @apiName PutLink
 * @apiGroup Link
 * @apiParam {String} token
 * @apiParam {Array} references
 */
router.put('/:token', auth, async (ctx: any) => {
    const {token} = ctx.params;
    const {body} = ctx.request;
    const [link, created] = await models.link.findOrCreate({ where: { token } });
    if (body.references) {
        link.set('references', JSON.stringify(body.references));
    }
    if (body.token) {
        link.set('token', body.token);
    }
    await link.save();
    ctx.body = 'OK';
});

/**
 * @api {DELETE} /:token Delete link
 * @apiName DeleteLink
 * @apiGroup Link
 */
router.delete('/:token', auth, async (ctx) => {
    const {token} = ctx.params;
    const link = await models.link.findOne({ where: { token } });
開發者ID:CatchLabs,項目名稱:simple-redir,代碼行數:31,代碼來源:index.ts

示例6: function

    try {
         const question = await questionToSave.save<IQuestion>();
         const tags = await Tag.find({value: { '$in': question.tags}}).exec();
        
         question.tags.forEach(async function(tag) {
             if (!tags.find((questionTag) => questionTag.value === tag)) {
                 const newTag = new Tag();
                 newTag.value = tag;
                 await newTag.save<ITag>();
             }
         });
         ctx.body = question;
    } catch (err) {
        ctx.response.status = 500;
        ctx.body = err.message;
    }
});

router.put('/:id', async function(ctx) {
    try {
        const {title, content} = ctx.request.body;
        const question = await Question.findById(ctx.params.id).exec();
        Object.assign(question, {title, content});
        ctx.body = await question.save();
    } catch(err) {
        ctx.response.status = 500;
        ctx.body = err.message;
    }
});

export default router;
開發者ID:DavidOnGitHub,項目名稱:questionApp_backend,代碼行數:31,代碼來源:question.ts

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

示例8: Koa

const app = new Koa()

const router = new Router()

router.get('/data', (ctx: Koa.Context) => {
    ctx.set('my-header', 'hello')
    ctx.body = {
        content: {},
        code: 200
    }
})
router.put('/data', (ctx: Koa.Context) => {
    ctx.set('my-header', 'hello')
    ctx.body = {
        content: {},
        code: 200
    }
})

app.use(cors({
    origin: (ctx: Koa.Context) => {
        const whiteList = ['http://localhost:3000']
        if (whiteList.includes(ctx.header.origin)) {
            return ctx.header.origin
        }
        return ''
    },
    exposeHeaders: 'my-header',
    allowMethods: 'PUT',
    allowHeaders: 'req-header',
開發者ID:YimYijet,項目名稱:WebTest,代碼行數:30,代碼來源:cors.ts

示例9: Router

import * as Router from 'koa-router';
import RootController from '../controller/root_controller';
import ProjectController from '../controller/project_controller';

const router = new Router();
router.get('/', RootController.getRootPage);
router.get('/api/projects/:id', ProjectController.getProject);
router.options('/api/projects/:id');
router.put('/api/projects/:id', ProjectController.updateProject);
router.get('/api/projects', ProjectController.getProjects);

export default router;
開發者ID:Ushinji,項目名稱:next_sample,代碼行數:12,代碼來源:index.ts

示例10: require

import * as Router from 'koa-router';
import { getManager } from 'typeorm';
import controller = require('./controller');

const router = new Router();

// GENERAL ROUTES
router.get('/', controller.general.helloWorld);
router.get('/jwt', controller.general.getJwtPayload);

// USER ROUTES
router.get('/users', controller.user.getUsers);
router.get('/user/:id', controller.user.getUser);
router.post('/user', controller.user.createUser);
router.put('/user/:id', controller.user.updateUser);
router.delete('/user/:id', controller.user.deleteUser);

export { router };
開發者ID:ryanwild,項目名稱:node-typescript-koa-rest,代碼行數:18,代碼來源:routes.ts


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