req.accespts(type)
req.accepts는 반환하기 가장 적절한 타입을 Accept HTTP Header를 근거로 결정한다.
만약 type 중 만족스러운 콘텐츠 형식이 없다면 false를 반환한다.
false를 반환하는 경우 응용 프로그램은 HTTP 상태 코드 406 "Not Acceptable"로 응답해야 한다.
// Accept: text/html
req.accepts('html');
// => "html"
// Accept: text/*, application/json
req.accepts('html');
// => "html"
req.accepts('text/html');
// => "text/html"
req.accepts(['json', 'text']);
// => "json"
req.accepts('application/json');
// => "application/json"
// Accept: text/*, application/json
req.accepts('image/png');
req.accepts('png');
// => undefined ( 만족스러운 결과가 없음 )
// Accept: text/*;q=.5, application/json
req.accepts(['html', 'json']);
// => "json"
출처 [http://expressjs.com/en/4x/api.html#req.accepts]
틀리거나 애매한 부분이 있다면 댓글로 알려주세요.