Accepts 헬퍼
Accepts 헬퍼는 요청의 Accept 헤더를 처리하는 데 도움을 준다.
Import
ts
import { Hono } from 'hono'
import { accepts } from 'hono/accepts'accepts()
accepts() 함수는 Accept-Encoding, Accept-Language와 같은 Accept 헤더를 확인하고 적절한 값을 반환한다.
ts
import { accepts } from 'hono/accepts'
app.get('/', (c) => {
const accept = accepts(c, {
header: 'Accept-Language',
supports: ['en', 'ja', 'zh'],
default: 'en',
})
return c.json({ lang: accept })
})AcceptHeader 타입
AcceptHeader 타입의 정의는 다음과 같다.
ts
export type AcceptHeader =
| 'Accept'
| 'Accept-Charset'
| 'Accept-Encoding'
| 'Accept-Language'
| 'Accept-Patch'
| 'Accept-Post'
| 'Accept-Ranges'옵션
required 헤더: AcceptHeader
대상 accept 헤더를 지정한다.
필수 supports: string[]
애플리케이션이 지원하는 헤더 값들.
필수 default: string
기본값을 설정한다.
optional match: (accepts: Accept[], config: acceptsConfig) => string
커스텀 매치 함수.