Unverified Commit a2fa637a authored by Jeff's avatar Jeff Committed by GitHub

fix(types): add missing ua types for NextRequest (#31901)

* fix(types): add missing ua type for NextRequest

add missing ua string type on NextRequest["ua"], returns full agent as string

* Update UserAgent type
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent b290a3dc
import type { I18NConfig } from '../../config-shared'
import type { IResult } from 'next/dist/compiled/ua-parser-js'
import type { RequestData } from '../types'
import { NextURL } from '../next-url'
import { isBot } from '../../utils'
......@@ -110,6 +109,27 @@ export interface RequestInit extends globalThis.RequestInit {
}
}
interface UserAgent extends IResult {
interface UserAgent {
isBot: boolean
ua: string
browser: {
name?: string
version?: string
}
device: {
model?: string
type?: string
vendor?: string
}
engine: {
name?: string
version?: string
}
os: {
name?: string
version?: string
}
cpu: {
architecture?: string
}
}
import { NextMiddleware } from 'next/server'
export const middleware: NextMiddleware = function (request) {
console.log(request.ua?.browser)
console.log(request.ua?.isBot)
console.log(request.ua?.ua)
return new Response(null, {
headers: {
'req-url-basepath': request.nextUrl.basePath,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment