Skip to content

Commit e9ae6fc

Browse files
committed
Updating force-relative-redirects so that it only affects redirects to LabelZoom.net
1 parent 5188e87 commit e9ae6fc

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "labelzoom-cf-api-proxy",
33
"description": "A Cloudflare Worker that serves as a reverse proxy for LabelZoom's public REST API",
4-
"version": "1.1.2",
4+
"version": "1.1.3",
55
"private": true,
66
"dependencies": {
77
"hono": "4.7.7",

src/worker/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ app.notFound((c) => {
100100
return proxyToBackend({
101101
baseUrl: c.env.LZ_PROD_API_BASE_URL,
102102
headers: {
103-
'X-LZ-IP': c.req.header("Cf-Connecting-Ip") || c.req.header("X-Forwarded-For") || '',
103+
'X-LZ-IP': c.req.header("CF-Connecting-IP") || c.req.header("X-Forwarded-For") || '',
104104
'X-LZ-Secret-Key': c.env.LZ_PROD_API_SECRET_KEY,
105105
},
106106
})(c);

src/worker/middleware/force-relative-redirects.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export const forceRelativeRedirects = (): MiddlewareHandler => {
1515
const url = new URL(locationHeader); // throws TypeError if not a full URL
1616

1717
// URL parsed successfully, it's an absolute redirect rather than relative
18-
c.res.headers.set('Location', url.pathname + url.search);
18+
if (/\.?labelzoom.net$/.test(url.host)) {
19+
c.res.headers.set('Location', url.pathname + url.search);
20+
}
1921
} catch {
2022
// failed to parse location header as URL, it's already a relative redirect (so do nothing)
2123
}

0 commit comments

Comments
 (0)