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:
Jeff 2021-11-30 16:59:02 -05:00 committed by GitHub
parent b290a3dc38
commit a2fa637ab3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -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
}
} }

View file

@ -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,