我是一个相对的初学者.我现在有两个单独的API调用(getPlayerAge和getPlayerRank),但我试图将这两个调用合并到一个端点(GetBothPlayerAgeAndRank)中,以便两个结果都在一个JSON中.我在ANGLE,TYPESCRIPT,Express,Node.js工作.我怎么做才能得到返回[getPlayerAge,getPlayerRank]?
import * as Promise from 'bluebird';
import { Request, Response, Router } from 'express';
import * as https from 'https';
import * as http from 'http';
import * as apicache from 'apicache';
import { PlayerModule } from '../modules';
const router = Router();
const cache = apicache.middleware;
router.get('/getPlayerAge', (req: Request, res: Response, next: () => void) => {
let playerName: string;
if (!req.query.player) {
res.json([]);
next();
} else {
playerName = req.query.player;
PlayerModule.getPlayerAge(playerName)
.then((results) => {
if (results.length > 0) {
res.json(results[0]);
} else {
res.sendStatus(404);
}
})
.catch((reason) => {
//console.error(reason);
res.sendStatus(500);
})
.finally(next);
}
});
router.get('/getPlayerRank', (req: Request, res: Response, next: () => void) => {
let playerName: string;
if (!req.query.player) {
res.json([]);
next();
} else {
playerName = req.query.player;
PlayerModule.getPlayerRank(playerName)
.then((results) => {
if (results.length > 0) {
res.json(results[0]);
} else {
res.sendStatus(404);
}
})
.catch((reason) => {
//console.error(reason);
res.sendStatus(500);
})
.finally(next);
}
});
export const PlayerRoutes = router;