From 90a002979f44915e757d193f3b534993ae601e8b Mon Sep 17 00:00:00 2001 From: wiz Date: Tue, 22 Apr 2025 15:04:38 +0900 Subject: [PATCH 1/5] ops: Add global /twidget path for twitter widget --- production/nginx/server-common.conf | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/production/nginx/server-common.conf b/production/nginx/server-common.conf index 5a0b17b4e..7b5c1524c 100644 --- a/production/nginx/server-common.conf +++ b/production/nginx/server-common.conf @@ -125,6 +125,27 @@ location /slurp/ { try_files /dev/null @mempool-space-slurper; } +# add hack for twitter widget + +location ~ ^/twidget/([a-z0-9_])*$ { + proxy_pass https://syndication.twitter.com/srv/timeline-profile/screen-name/$1?creatorScreenName=mempool&dnt=true&embedId=twitter-widget-0&features=eyJ0ZndfdGltZWxpbmVfgbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&frame=false&hideBorder=true&hideFooter=false&hideHeader=true&hideScrollBar=false&lang=en&maxHeight=500px&origin=$scheme%3A%2F%2F$http_host%2F&showHeader=false&showReplies=false&siteScreenName=mempool&theme=dark&transparent=true&widgetsVersion=2615f7e52b7e0%3A1702314776716; + + proxy_ssl_server_name on; + + proxy_cache_background_update on; + proxy_cache_use_stale http_429; + proxy_cache apicold; + proxy_cache_valid 200 60s; + + proxy_redirect off; + + add_header 'Pragma' 'no-cache'; + add_header 'Cache-Control' 'private, no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; + + expires -1; +} + + # catch-all for all URLs i.e. /address/foo /tx/foo /block/000 # cache 5 minutes since they change frequently location / { From 384e0feec110e99342353b14751bb27f627601b1 Mon Sep 17 00:00:00 2001 From: wiz Date: Tue, 22 Apr 2025 15:10:01 +0900 Subject: [PATCH 2/5] Use new /twidget/username hack in frontend code --- .../twitter-widget.component.ts | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/frontend/src/app/components/twitter-widget/twitter-widget.component.ts b/frontend/src/app/components/twitter-widget/twitter-widget.component.ts index 8f5894ad0..8be182e8a 100644 --- a/frontend/src/app/components/twitter-widget/twitter-widget.component.ts +++ b/frontend/src/app/components/twitter-widget/twitter-widget.component.ts @@ -37,35 +37,7 @@ export class TwitterWidgetComponent implements OnChanges { if (!this.handle) { return; } - let url = `https://syndication.x.com/srv/timeline-profile/screen-name/${this.handle}?creatorScreenName=mempool` - + '&dnt=true' - + '&embedId=twitter-widget-0' - + '&features=eyJ0ZndfdGltZWxpbmVfgbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D' - + '&frame=false' - + '&hideBorder=true' - + '&hideFooter=false' - + '&hideHeader=true' - + '&hideScrollBar=false' - + `&lang=${this.lang}` - + '&maxHeight=500px' - + '&origin=https%3A%2F%2Fmempool.space%2F' - // + '&sessionId=88f6d661d0dcca99c43c0a590f6a3e61c89226a9' - + '&showHeader=false' - + '&showReplies=false' - + '&siteScreenName=mempool' - + '&theme=dark' - + '&transparent=true' - + '&widgetsVersion=2615f7e52b7e0%3A1702314776716'; - switch (this.handle.toLowerCase()) { - case 'nayibbukele': - url = 'https://bitcoin.gob.sv/twidget'; - break; - case 'metaplanet_jp': - url = 'https://metaplanet.mempool.space/twidget'; - break; - default: - break; - } + let url = `/twidget/${this.handle}`; this.iframeSrc = this.sanitizer.bypassSecurityTrustResourceUrl(this.sanitizer.sanitize(SecurityContext.URL, url)); } From 95df451482466ededd526bd8c6b885b855cce7a8 Mon Sep 17 00:00:00 2001 From: wiz Date: Tue, 22 Apr 2025 15:19:33 +0900 Subject: [PATCH 3/5] ops: Fix regex in nginx /twidget location pattern --- production/nginx/server-common.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/production/nginx/server-common.conf b/production/nginx/server-common.conf index 7b5c1524c..e6d0fa5ce 100644 --- a/production/nginx/server-common.conf +++ b/production/nginx/server-common.conf @@ -127,7 +127,7 @@ location /slurp/ { # add hack for twitter widget -location ~ ^/twidget/([a-z0-9_])*$ { +location ~ ^/twidget/([a-z0-9_]*)$ { proxy_pass https://syndication.twitter.com/srv/timeline-profile/screen-name/$1?creatorScreenName=mempool&dnt=true&embedId=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idWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&frame=false&hideBorder=true&hideFooter=false&hideHeader=true&hideScrollBar=false&lang=en&maxHeight=500px&origin=$scheme%3A%2F%2F$http_host%2F&showHeader=false&showReplies=false&siteScreenName=mempool&theme=dark&transparent=true&widgetsVersion=2615f7e52b7e0%3A1702314776716; proxy_ssl_server_name on; From a683cbc1da63b968d833b4a219eb0e747dc01c47 Mon Sep 17 00:00:00 2001 From: wiz Date: Tue, 22 Apr 2025 15:41:00 +0900 Subject: [PATCH 4/5] ops: Fix regex case matching in nginx /twidget location --- production/nginx/server-common.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/production/nginx/server-common.conf b/production/nginx/server-common.conf index e6d0fa5ce..71b09e404 100644 --- a/production/nginx/server-common.conf +++ b/production/nginx/server-common.conf @@ -127,7 +127,7 @@ location /slurp/ { # add hack for twitter widget -location ~ ^/twidget/([a-z0-9_]*)$ { +location ~ ^/twidget/([A-z0-9_]*)$ { proxy_pass https://syndication.twitter.com/srv/timeline-profile/screen-name/$1?creatorScreenName=mempool&dnt=true&embedId=twitter-widget-0&features=eyJ0ZndfdGltZWxpbmVfgbGlzdCI6eyJidWNrZXQiOltdLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X2ZvbGxvd2VyX2NvdW50X3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9iYWNrZW5kIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19yZWZzcmNfc2Vzc2lvbiI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfZm9zbnJfc29mdF9pbnRlcnZlbnRpb25zX2VuYWJsZWQiOnsiYnVja2V0Ijoib24iLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X21peGVkX21lZGlhXzE1ODk3Ijp7ImJ1Y2tldCI6InRyZWF0bWVudCIsInZlcnNpb24iOm51bGx9LCJ0ZndfZXhwZXJpbWVudHNfY29va2llX2V4cGlyYXRpb24iOnsiYnVja2V0IjoxMjA5NjAwLCJ2ZXJzaW9uIjpudWxsfSwidGZ3X3Nob3dfYmlyZHdhdGNoX3Bpdm90c19lbmFibGVkIjp7ImJ1Y2tldCI6Im9uIiwidmVyc2lvbiI6bnVsbH0sInRmd19kdXBsaWNhdGVfc2NyaWJlc190b19zZXR0aW5ncyI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdXNlX3Byb2ZpbGVfaW1hZ2Vfc2hhcGVfZW5hYmxlZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9LCJ0ZndfdmlkZW9faGxzX2R5bmFtaWNfbWFuaWZlc3RzXzE1MDgyIjp7ImJ1Y2tldCI6InRydWVfYml0cmF0ZSIsInZlcnNpb24iOm51bGx9LCJ0ZndfbGVnYWN5X3RpbWVsaW5lX3N1bnNldCI6eyJidWNrZXQiOnRydWUsInZlcnNpb24iOm51bGx9LCJ0ZndfdHdlZXRfZWRpdF9mcm9udGVuZCI6eyJidWNrZXQiOiJvbiIsInZlcnNpb24iOm51bGx9fQ%3D%3D&frame=false&hideBorder=true&hideFooter=false&hideHeader=true&hideScrollBar=false&lang=en&maxHeight=500px&origin=$scheme%3A%2F%2F$http_host%2F&showHeader=false&showReplies=false&siteScreenName=mempool&theme=dark&transparent=true&widgetsVersion=2615f7e52b7e0%3A1702314776716; proxy_ssl_server_name on; From c8f3aa530ea121b6bc88f138c63a417ac80111ae Mon Sep 17 00:00:00 2001 From: wiz Date: Tue, 22 Apr 2025 17:19:59 +0900 Subject: [PATCH 5/5] Change frontend /twidget to /api/v1/services/x/:handle --- .../app/components/twitter-widget/twitter-widget.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/app/components/twitter-widget/twitter-widget.component.ts b/frontend/src/app/components/twitter-widget/twitter-widget.component.ts index 8be182e8a..0890c2135 100644 --- a/frontend/src/app/components/twitter-widget/twitter-widget.component.ts +++ b/frontend/src/app/components/twitter-widget/twitter-widget.component.ts @@ -37,7 +37,7 @@ export class TwitterWidgetComponent implements OnChanges { if (!this.handle) { return; } - let url = `/twidget/${this.handle}`; + let url = `/api/v1/services/x/${this.handle}`; this.iframeSrc = this.sanitizer.bypassSecurityTrustResourceUrl(this.sanitizer.sanitize(SecurityContext.URL, url)); }