From 0762e41e83b6a8381c9a5bf998691b5f723289e8 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Wed, 18 Mar 2026 16:18:23 +0100 Subject: [PATCH] fix(workflows): follow HTTP redirects in PocketBase request function --- .github/workflows/push_json_to_pocketbase.yml | 10 +++++++++- .github/workflows/update-timestamp-on-db.yml | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/push_json_to_pocketbase.yml b/.github/workflows/push_json_to_pocketbase.yml index aa329d98b..bbea10dc4 100644 --- a/.github/workflows/push_json_to_pocketbase.yml +++ b/.github/workflows/push_json_to_pocketbase.yml @@ -49,7 +49,8 @@ jobs: const https = require('https'); const http = require('http'); const url = require('url'); - function request(fullUrl, opts) { + function request(fullUrl, opts, redirectCount) { + redirectCount = redirectCount || 0; return new Promise(function(resolve, reject) { const u = url.parse(fullUrl); const isHttps = u.protocol === 'https:'; @@ -64,6 +65,13 @@ jobs: if (body) options.headers['Content-Length'] = Buffer.byteLength(body); const lib = isHttps ? https : http; const req = lib.request(options, function(res) { + if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { + if (redirectCount >= 5) return reject(new Error('Too many redirects from ' + fullUrl)); + const redirectUrl = url.resolve(fullUrl, res.headers.location); + res.resume(); + resolve(request(redirectUrl, opts, redirectCount + 1)); + return; + } let data = ''; res.on('data', function(chunk) { data += chunk; }); res.on('end', function() { diff --git a/.github/workflows/update-timestamp-on-db.yml b/.github/workflows/update-timestamp-on-db.yml index 5716e6b60..b68c69eaa 100644 --- a/.github/workflows/update-timestamp-on-db.yml +++ b/.github/workflows/update-timestamp-on-db.yml @@ -83,7 +83,8 @@ jobs: const http = require('http'); const url = require('url'); - function request(fullUrl, opts) { + function request(fullUrl, opts, redirectCount) { + redirectCount = redirectCount || 0; return new Promise(function(resolve, reject) { const u = url.parse(fullUrl); const isHttps = u.protocol === 'https:'; @@ -98,6 +99,13 @@ jobs: if (body) options.headers['Content-Length'] = Buffer.byteLength(body); const lib = isHttps ? https : http; const req = lib.request(options, function(res) { + if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { + if (redirectCount >= 5) return reject(new Error('Too many redirects from ' + fullUrl)); + const redirectUrl = url.resolve(fullUrl, res.headers.location); + res.resume(); + resolve(request(redirectUrl, opts, redirectCount + 1)); + return; + } let data = ''; res.on('data', function(chunk) { data += chunk; }); res.on('end', function() {