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: JJ Kasper <jj@jjsweb.site>
This commit is contained in:
parent
b290a3dc38
commit
a2fa637ab3
2 changed files with 26 additions and 2 deletions
|
@ -1,5 +1,4 @@
|
||||||
import type { I18NConfig } from '../../config-shared'
|
import type { I18NConfig } from '../../config-shared'
|
||||||
import type { IResult } from 'next/dist/compiled/ua-parser-js'
|
|
||||||
import type { RequestData } from '../types'
|
import type { RequestData } from '../types'
|
||||||
import { NextURL } from '../next-url'
|
import { NextURL } from '../next-url'
|
||||||
import { isBot } from '../../utils'
|
import { isBot } from '../../utils'
|
||||||
|
@ -110,6 +109,27 @@ export interface RequestInit extends globalThis.RequestInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserAgent extends IResult {
|
interface UserAgent {
|
||||||
isBot: boolean
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import { NextMiddleware } from 'next/server'
|
import { NextMiddleware } from 'next/server'
|
||||||
|
|
||||||
export const middleware: NextMiddleware = function (request) {
|
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, {
|
return new Response(null, {
|
||||||
headers: {
|
headers: {
|
||||||
'req-url-basepath': request.nextUrl.basePath,
|
'req-url-basepath': request.nextUrl.basePath,
|
||||||
|
|
Loading…
Reference in a new issue