userAgent
userAgentヘルパーは、Web Request APIを拡張し、リクエストからユーザーエージェントオブジェクトを操作するための追加のプロパティとメソッドを提供します。
proxy.ts
import { NextRequest, NextResponse, userAgent } from 'next/server'
export function proxy(request: NextRequest) {
const url = request.nextUrl
const { device } = userAgent(request)
// device.type can be: 'mobile', 'tablet', 'console', 'smarttv',
// 'wearable', 'embedded', or undefined (for desktop browsers)
const viewport = device.type || 'desktop'
url.searchParams.set('viewport', viewport)
return NextResponse.rewrite(url)
}isBot
リクエストが既知のボットからのものかを示すブール値。
browser
リクエストで使用されたブラウザに関する情報を含むオブジェクト。
name: ブラウザの名前を表す文字列、または識別できない場合はundefined。version: ブラウザのバージョンを表す文字列、またはundefined。
device
リクエストで使用されたデバイスに関する情報を含むオブジェクト。
model: デバイスのモデルを表す文字列、またはundefined。type:console、mobile、tablet、smarttv、wearable、embedded、またはundefinedなどのデバイスの種類を表す文字列。vendor: デバイスのベンダーを表す文字列、またはundefined。
engine
ブラウザのエンジンに関する情報を含むオブジェクト。
name: エンジンの名前を表す文字列。可能な値には、Amaya、Blink、EdgeHTML、Flow、Gecko、Goanna、iCab、KHTML、Links、Lynx、NetFront、NetSurf、Presto、Tasman、Trident、w3m、WebKit、またはundefinedが含まれます。version: エンジンのバージョンを表す文字列、またはundefined。
os
オペレーティングシステムに関する情報を含むオブジェクト。
name: OSの名前を表す文字列、またはundefined。version: OSのバージョンを表す文字列、またはundefined。
cpu
CPUアーキテクチャに関する情報を含むオブジェクト。
architecture: CPUのアーキテクチャを表す文字列。可能な値には、68k、amd64、arm、arm64、armhf、avr、ia32、ia64、irix、irix64、mips、mips64、pa-risc、ppc、sparc、sparc64、またはundefinedが含まれます。
役に立ちましたか?