Skip to content

Commit 18b0e0a

Browse files
authored
Merge pull request #357 from Quickchive/chore/QA-356/improve-og-crawling
chore: add user agent header to axios
2 parents dc6d5f4 + 0fd5602 commit 18b0e0a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/contents/util/content.util.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@ export const getLinkInfo = async (link: string) => {
1414

1515
// ! TODO 크롤링에서 대략 초 단위 시간 소요 -> 개선 필요
1616
await axios
17-
.get(link)
17+
.get(link, {
18+
headers: {
19+
'User-Agent': 'Mozilla/5.0 (compatible; OGCrawler/1.0)',
20+
},
21+
})
1822
.then((res) => {
1923
if (res.status !== 200) {
2024
throw new BadRequestException('잘못된 링크입니다.');
2125
} else {
2226
const data = res.data;
2327
if (typeof data === 'string') {
2428
const $ = cheerio.load(data);
25-
title = $('title').text() !== '' ? $('title').text() : 'Untitled';
29+
title =
30+
$('title').text() !== ''
31+
? $('title').text() || $('meta[name="title"]').attr('content')
32+
: 'Untitled';
2633
$('meta').each((i, el) => {
2734
const meta = $(el);
2835
if (meta.attr('property') === 'og:image') {

0 commit comments

Comments
 (0)