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