forked from Coflnet/hypixel-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_middleware.tsx
More file actions
22 lines (21 loc) · 739 Bytes
/
_middleware.tsx
File metadata and controls
22 lines (21 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { NextFetchEvent, NextRequest, NextResponse } from 'next/server'
import api from './api/ApiHelper'
export async function middleware(req: NextRequest, ev: NextFetchEvent) {
if (req.nextUrl.pathname.startsWith('/player')) {
const url = req.nextUrl.clone()
let split = url.pathname.split('/')
if (split[2].length < 30) {
await api
.playerSearch(split[2])
.then(players => {
split[2] = players[0].uuid
})
.catch(() => {
split[2] = ''
})
url.pathname = split.join('/')
return NextResponse.redirect(url)
}
}
return NextResponse.next()
}