mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 03:29:51 +01:00
feat: CORS proxy for neighbors
This commit is contained in:
1 parent
4f62a594b3
commit
15bf02f829
3 files changed
+13
-18
No files matched your search
@@ -1,12 +0,0 @@
|
|||||||
import { NextResponse } from 'next/server';
|
|
||||||
import { Region } from '../../../../../../../../constants/regions';
|
|
||||||
import { getRatingsNeighbors } from '../../../../../../../../core/blitz/getRatingsNeighbors';
|
|
||||||
|
|
||||||
export async function GET(
|
|
||||||
request: Request,
|
|
||||||
{ params }: { params: { region: Region; id: number; count: number } },
|
|
||||||
) {
|
|
||||||
return NextResponse.json(
|
|
||||||
await getRatingsNeighbors(params.region, params.id, params.count),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { RatingsNeighbors } from '../../commands/ratings';
|
import { RatingsNeighbors } from '../../commands/ratings';
|
||||||
import { Region } from '../../constants/regions';
|
import { Region } from '../../constants/regions';
|
||||||
import { context } from '../blitzkrieg/context';
|
|
||||||
import { patientFetch } from '../blitzkrieg/patientFetch';
|
import { patientFetch } from '../blitzkrieg/patientFetch';
|
||||||
|
import { withCORSProxy } from '../blitzkrieg/withCORSProxy';
|
||||||
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
import regionToRegionSubdomain from './regionToRegionSubdomain';
|
||||||
|
|
||||||
export async function getRatingsNeighbors(
|
export async function getRatingsNeighbors(
|
||||||
@@ -12,11 +12,11 @@ export async function getRatingsNeighbors(
|
|||||||
) {
|
) {
|
||||||
const fetcher = usePatientFetcher ? patientFetch : fetch;
|
const fetcher = usePatientFetcher ? patientFetch : fetch;
|
||||||
const response = await fetcher(
|
const response = await fetcher(
|
||||||
context === 'website'
|
withCORSProxy(
|
||||||
? `/api/${region}/ratings/current/neighbors/${id}/${count}`
|
`https://${regionToRegionSubdomain(
|
||||||
: `https://${regionToRegionSubdomain(
|
region,
|
||||||
region,
|
)}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${count}`,
|
||||||
)}.wotblitz.com/en/api/rating-leaderboards/user/${id}/?neighbors=${count}`,
|
),
|
||||||
);
|
);
|
||||||
const json = (await response.json()) as RatingsNeighbors;
|
const json = (await response.json()) as RatingsNeighbors;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { context } from './context';
|
||||||
|
|
||||||
|
export function withCORSProxy(url: string) {
|
||||||
|
return context === 'website'
|
||||||
|
? `https://corsproxy.io/?${encodeURIComponent(url)}`
|
||||||
|
: url;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user