Fix googlebot user-agent detection

This commit is contained in:
Mononaut 2023-02-27 10:48:13 -06:00
parent 2f27d9279d
commit b1e32ed55f
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E

View File

@ -222,7 +222,7 @@ class Server {
|| rawPath.startsWith('/api/v1/translators/images')
|| rawPath.startsWith('/resources/profile')
) {
if (req.headers['user-agent'] === 'googlebot') {
if (isSearchCrawler(req.headers['user-agent'])) {
if (this.secureHost) {
https.get(config.SERVER.HOST + rawPath, { headers: { 'user-agent': 'mempoolunfurl' }}, (got) => got.pipe(res));
} else {
@ -237,7 +237,7 @@ class Server {
let result = '';
try {
if (req.headers['user-agent'] === 'googlebot') {
if (isSearchCrawler(req.headers['user-agent'])) {
result = await this.renderSEOPage(rawPath);
} else {
result = await this.renderUnfurlMeta(rawPath);
@ -313,3 +313,7 @@ function capitalize(str) {
return str;
}
}
function isSearchCrawler(useragent: string): boolean {
return /googlebot/i.test(useragent);
}