本文整理汇总了TypeScript中koa-router.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: Router
const router = new Router()
function getData(): Promise<any> {
return new Promise((resolve, reject) => {
request.get('https://store.steampowered.com/stats/').end((err, res) => {
if (err) {
reject(err)
}
const $ = cheerio.load(res.text), temp: object[] = []
$('#detailStats tbody tr').each((index, item) => {
temp.push({
cur: $(item).find('td:first-child').text().trim(),
name: $(item).find('td:last-child').text().trim(),
peak: $(item).find('td:nth-child(2)').text().trim(),
})
})
resolve(temp)
})
})
}
router.get('/', async (ctx: Koa.Context, next: () => void) => {
ctx.body = await getData()
})
app.use(router.routes())
http.createServer(app.callback()).listen(3344, () => {
console.log(`http server listening on port: 3344`)
})
开发者ID:YimYijet,项目名称:WebTest,代码行数:30,代码来源:app.ts
示例2: Router
const router = new Router({
prefix: "/users"
});
router
.param('id', function(id, ctx, next) {
next();
})
.get('/', function (ctx, next) {
ctx.body = 'Hello World!';
})
.post('/users', function (ctx, next) {
// ...
})
.put('/users/:id', function (ctx, next) {
ctx.body = ctx.params.id;
})
.del('/users/:id', function () {
// ...
});
router.get('user', '/users/:id', function (ctx) {
ctx.body = "sdsd";
});
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(3000);
开发者ID:Agamnentzar,项目名称:DefinitelyTyped,代码行数:29,代码来源:koa-router-tests.ts
示例3: getUserToken
router.get('/disconnect/twitter', async ctx => {
if (!compareOrigin(ctx)) {
ctx.throw(400, 'invalid origin');
return;
}
const userToken = getUserToken(ctx);
if (userToken == null) {
ctx.throw(400, 'signin required');
return;
}
const user = await User.findOneAndUpdate({
host: null,
'token': userToken
}, {
$set: {
'twitter': null
}
});
ctx.body = `Twitterの連携を解除しました :v:`;
// Publish i updated event
publishUserStream(user._id, 'meUpdated', await pack(user, user, {
detail: true,
includeSecrets: true
}));
});
开发者ID:ha-dai,项目名称:Misskey,代码行数:29,代码来源:twitter.ts
示例4: KoaRouter
import { getAll, getHash, getPictureFileName, getRandomPicture, getSpecificPicture } from './pictures';
import config from './config';
import KoaRouter from 'koa-router';
const router = new KoaRouter();
const postUri = config.postUri;
router
.get('/', async ctx => {
const cat = await getRandomPicture();
ctx.body = cat.file;
ctx.set('cat', cat.fileName);
ctx.response.type = cat.type;
})
.get('/thumb', async ctx => {
const cat = await getRandomPicture(true);
ctx.body = cat.file;
ctx.set('cat', cat.fileName);
ctx.response.type = cat.type;
})
.get('/specific', async ctx => {
ctx.body = await getPictureFileName();
})
.get('/specific/:id', async ctx => {
const { id } = ctx.params;
const cat = await getSpecificPicture(id);
ctx.body = cat.file;
ctx.set('cat', cat.fileName);
开发者ID:marudor,项目名称:randomCats,代码行数:31,代码来源:controller.ts
示例5: Router
import * as Router from 'koa-router'
import ApiHandle from './api'
const router: Router = new Router()
router
.get('/', async (ctx, next) => {
ctx.body = '!!!'
})
// mock web UI api
.get('/api/:what/:type', ApiHandle)
.post('/api/:what/:type', ApiHandle)
.del('/api/:what/:type', ApiHandle)
.put('/api/:what/:type', ApiHandle)
.options('/api/:what/:type', ApiHandle)
export default router
开发者ID:Jecen,项目名称:Venus_Node_Service,代码行数:17,代码来源:index.ts
示例6: Router
const router = new Router();
// router.get("/api/v1/players", Player.getAllPlayers);
// router.get("/api/v1/player/:name", Player.getPlayerByName);
// router.get("/api/v1/matches", Match.getAllMatchs);
// router.get("/api/v1/match/:id", Match.getOneMatchById);
// router.post("/api/v1/addmatch", Match.insertOneMatch);
// router.post("/api/v1/updatematch", Match.updateMatch);
// router.post("/api/v1/deletematch/:id", Match.deleteOneMatchById);
router.get("/wxsign", Sign.getWeixinSign);
// router
// .post("/api/v1/graphql", async (ctx: Context, next: any): Promise<void> => {
// await graphqlKoa({schema: schema})(ctx, next); // 使用schema
// })
// .get("/api/v1/graphql", async (ctx: Context, next: any): Promise<void> => {
// await graphqlKoa({schema: schema})(ctx, next); // 使用schema
// })
// .get("/api/v1/graphiql", async (ctx: Context, next: any): Promise<void> => {
// await graphiqlKoa({endpointURL: "/api/v1/graphql"})(ctx); // 重定向到graphiql路由
// });
export default router;
开发者ID:gaohan1994,项目名称:api.rankts,代码行数:30,代码来源:index.ts
示例7: 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
示例8: Router
import { ensureAuthenticated } from '../auth/authUtils';
import * as Router from 'koa-router';
import * as controller from './todo.controller';
const router = new Router();
// routes
router.use(['/', '/archived'], ensureAuthenticated);
router.get('/archived', controller.getAllNonArchived);
router.get('/', controller.getAll);
router.post('/', controller.createItem);
router.put('/:id', controller.updateItem);
router.post('/archive-all-completed', controller.archiveAllCompleted);
router.post('/purge-archived-items', controller.purgeArchiveItems);
router.post('/mark-all-completed/:flag', controller.toggleAllItemToComplete);
router.delete('/:id', controller.deleteItem);
export default router.routes();
开发者ID:ghiscoding,项目名称:Realtime-TODO-Aurelia-RethinkDB,代码行数:18,代码来源:index.ts
示例9: next
// Common request handler
app.use(async (ctx, next) => {
// IFrameの中に入れられないようにする
ctx.set('X-Frame-Options', 'DENY');
await next();
});
// Init router
const router = new Router();
//#region static assets
router.get('/assets/*', async ctx => {
await send(ctx, ctx.path, {
root: client,
maxage: ms('7 days'),
immutable: true
});
});
// Apple touch icon
router.get('/apple-touch-icon.png', async ctx => {
await send(ctx, '/assets/apple-touch-icon.png', {
root: client
});
});
// ServiceWroker
router.get(/^\/sw\.(.+?)\.js$/, async ctx => {
await send(ctx, `/assets/sw.${ctx.params[0]}.js`, {
root: client
开发者ID:ha-dai,项目名称:Misskey,代码行数:31,代码来源:index.ts
注:本文中的koa-router.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论