Switch unfurl proxy header to url prefix
This commit is contained in:
parent
681d4bffd7
commit
b1e1601ccf
@ -109,11 +109,15 @@ class Server {
|
|||||||
|
|
||||||
setUpRoutes() {
|
setUpRoutes() {
|
||||||
if (puppeteerEnabled) {
|
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) })
|
this.app.get('/render*', async (req, res) => { return this.renderPreview(req, res) })
|
||||||
} else {
|
} 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('/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 } }) {
|
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
|
// drop requests for static files
|
||||||
const rawPath = req.params[0];
|
const rawPath = req.params[0];
|
||||||
const match = rawPath.match(/\.[\w]+$/);
|
const match = rawPath.match(/\.[\w]+$/);
|
||||||
@ -250,7 +254,7 @@ class Server {
|
|||||||
|| rawPath.startsWith('/api/v1/translators/images')
|
|| rawPath.startsWith('/api/v1/translators/images')
|
||||||
|| rawPath.startsWith('/resources/profile')
|
|| rawPath.startsWith('/resources/profile')
|
||||||
) {
|
) {
|
||||||
if (isPreviewCrawler(req)) {
|
if (unfurl) {
|
||||||
res.status(404).send();
|
res.status(404).send();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -265,7 +269,7 @@ class Server {
|
|||||||
|
|
||||||
let result = '';
|
let result = '';
|
||||||
try {
|
try {
|
||||||
if (isPreviewCrawler(req)) {
|
if (unfurl) {
|
||||||
result = await this.renderUnfurlMeta(rawPath);
|
result = await this.renderUnfurlMeta(rawPath);
|
||||||
} else {
|
} else {
|
||||||
result = await this.renderSEOPage(rawPath);
|
result = await this.renderSEOPage(rawPath);
|
||||||
@ -348,7 +352,3 @@ function capitalize(str) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isPreviewCrawler(req: Request): boolean {
|
|
||||||
return req?.header('X-Unfurl-Type') === 'preview';
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user