convert soft 404s to hard 404s in unfurler ssr

This commit is contained in:
Mononaut
2023-03-09 02:34:21 -06:00
parent 2f3e498906
commit 105cccf9b0
19 changed files with 90 additions and 9 deletions

View File

@@ -179,8 +179,15 @@ class Server {
await page.waitForNetworkIdle({
timeout: config.PUPPETEER.RENDER_TIMEOUT || 3000,
});
let html = await page.content();
return html;
const is404 = await page.evaluate(async () => {
return !!window['soft404'];
});
if (is404) {
return '404';
} else {
let html = await page.content();
return html;
}
} catch (e) {
if (e instanceof TimeoutError) {
let html = await page.content();
@@ -258,7 +265,11 @@ class Server {
result = await this.renderUnfurlMeta(rawPath);
}
if (result && result.length) {
res.send(result);
if (result === '404') {
res.status(404).send();
} else {
res.send(result);
}
} else {
res.status(500).send();
}