mirror of
https://github.com/mempool/mempool.git
synced 2025-01-19 05:34:03 +01:00
Switch unfurl proxy header to url prefix
This commit is contained in:
parent
681d4bffd7
commit
b1e1601ccf
@ -109,11 +109,15 @@ class Server {
|
||||
|
||||
setUpRoutes() {
|
||||
if (puppeteerEnabled) {
|
||||
this.app.get('/unfurl/render*', async (req, res) => { return this.renderPreview(req, res) })
|
||||
this.app.get('/render*', async (req, res) => { return this.renderPreview(req, res) })
|
||||
} else {
|
||||
this.app.get('/unfurl/render*', async (req, res) => { return this.renderDisabled(req, res) })
|
||||
this.app.get('/render*', async (req, res) => { return this.renderDisabled(req, res) })
|
||||
}
|
||||
this.app.get('*', (req, res) => { return this.renderHTML(req, res) })
|
||||
this.app.get('/unfurl*', (req, res) => { return this.renderHTML(req, res, true) })
|
||||
this.app.get('/slurp*', (req, res) => { return this.renderHTML(req, res, false) })
|
||||
this.app.get('*', (req, res) => { return this.renderHTML(req, res, false) })
|
||||
}
|
||||
|
||||
async clusterTask({ page, data: { url, path, action } }) {
|
||||
@ -240,7 +244,7 @@ class Server {
|
||||
}
|
||||
}
|
||||
|
||||
async renderHTML(req, res) {
|
||||
async renderHTML(req, res, unfurl: boolean = false) {
|
||||
// drop requests for static files
|
||||
const rawPath = req.params[0];
|
||||
const match = rawPath.match(/\.[\w]+$/);
|
||||
@ -250,7 +254,7 @@ class Server {
|
||||
|| rawPath.startsWith('/api/v1/translators/images')
|
||||
|| rawPath.startsWith('/resources/profile')
|
||||
) {
|
||||
if (isPreviewCrawler(req)) {
|
||||
if (unfurl) {
|
||||
res.status(404).send();
|
||||
return;
|
||||
} else {
|
||||
@ -265,7 +269,7 @@ class Server {
|
||||
|
||||
let result = '';
|
||||
try {
|
||||
if (isPreviewCrawler(req)) {
|
||||
if (unfurl) {
|
||||
result = await this.renderUnfurlMeta(rawPath);
|
||||
} else {
|
||||
result = await this.renderSEOPage(rawPath);
|
||||
@ -348,7 +352,3 @@ function capitalize(str) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
function isPreviewCrawler(req: Request): boolean {
|
||||
return req?.header('X-Unfurl-Type') === 'preview';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user