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


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

本文整理匯總了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;未經允許,請勿轉載。