@resonatehq/supabase 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +7 -0
- package/.github/workflows/cd.yaml +29 -0
- package/.github/workflows/ci.yaml +39 -0
- package/dist/index.js +26 -6
- package/package.json +1 -1
- package/src/index.ts +32 -7
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: cd
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [released]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
run:
|
|
9
|
+
name: release
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
id-token: write
|
|
13
|
+
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- uses: actions/setup-node@v4
|
|
20
|
+
with:
|
|
21
|
+
node-version: "20"
|
|
22
|
+
registry-url: "https://registry.npmjs.org"
|
|
23
|
+
|
|
24
|
+
# Ensure npm 11.5.1 or later is installed
|
|
25
|
+
- name: Update npm
|
|
26
|
+
run: npm install -g npm@latest
|
|
27
|
+
- run: npm install
|
|
28
|
+
- run: npm run build
|
|
29
|
+
- run: npm publish
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
|
|
3
|
+
permissions:
|
|
4
|
+
contents: read
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
push:
|
|
9
|
+
branches: [main]
|
|
10
|
+
paths-ignore:
|
|
11
|
+
- README.md
|
|
12
|
+
pull_request:
|
|
13
|
+
branches: [main]
|
|
14
|
+
paths-ignore:
|
|
15
|
+
- README.md
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
run:
|
|
19
|
+
runs-on: ${{ matrix.os }}
|
|
20
|
+
timeout-minutes: 25
|
|
21
|
+
|
|
22
|
+
strategy:
|
|
23
|
+
fail-fast: true
|
|
24
|
+
matrix:
|
|
25
|
+
os: [ubuntu-latest, macos-latest]
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
|
|
30
|
+
- name: Set up Bun
|
|
31
|
+
uses: oven-sh/setup-bun@v2
|
|
32
|
+
with:
|
|
33
|
+
bun-version: 1.3.0
|
|
34
|
+
|
|
35
|
+
- name: install
|
|
36
|
+
run: bun install
|
|
37
|
+
|
|
38
|
+
- name: check linting
|
|
39
|
+
run: bun run check
|
package/dist/index.js
CHANGED
|
@@ -27,7 +27,6 @@ class Resonate {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
const url = buildForwardedURL(req);
|
|
30
|
-
console.log("URL", url);
|
|
31
30
|
const body = await req.json();
|
|
32
31
|
if (!req.body) {
|
|
33
32
|
return new Response(JSON.stringify({
|
|
@@ -110,9 +109,30 @@ class Resonate {
|
|
|
110
109
|
}
|
|
111
110
|
exports.Resonate = Resonate;
|
|
112
111
|
function buildForwardedURL(req) {
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
const headers = req.headers;
|
|
113
|
+
const url = new URL(req.url);
|
|
114
|
+
// 1. Hostname Logic
|
|
115
|
+
// Dev: "x-forwarded-host" is present (e.g., 127.0.0.1)
|
|
116
|
+
// Prod: "x-forwarded-host" is missing, so we use url.hostname (e.g., project.supabase.co)
|
|
117
|
+
const forwardedHost = headers.get("x-forwarded-host");
|
|
118
|
+
const host = forwardedHost ?? url.hostname;
|
|
119
|
+
// 2. Protocol Logic
|
|
120
|
+
// Always prefer "x-forwarded-proto" (usually https in prod), fallback to "http"
|
|
121
|
+
const proto = headers.get("x-forwarded-proto") ?? "http";
|
|
122
|
+
// 3. Port Logic
|
|
123
|
+
// Dev: We need the port (e.g., :54321).
|
|
124
|
+
// Prod: We rarely need :443 explicitly in the URL string.
|
|
125
|
+
const forwardedPort = headers.get("x-forwarded-port");
|
|
126
|
+
const port = (forwardedHost && forwardedPort) ? `:${forwardedPort}` : "";
|
|
127
|
+
// 4. Path Logic
|
|
128
|
+
// Dev: "x-forwarded-path" contains the full path (/functions/v1/hello-world)
|
|
129
|
+
// Prod: We must use url.pathname.
|
|
130
|
+
let path = headers.get("x-forwarded-path") ?? url.pathname;
|
|
131
|
+
// 5. Production Path Fix
|
|
132
|
+
// In Prod, the internal req.url often strips '/functions/v1'.
|
|
133
|
+
// We re-add it if we are in Prod (no forwardedHost) and it's missing.
|
|
134
|
+
if (!forwardedHost && !path.startsWith("/functions/v1")) {
|
|
135
|
+
path = `/functions/v1${path}`;
|
|
136
|
+
}
|
|
137
|
+
return `${proto}://${host}${port}${path}`;
|
|
118
138
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -77,7 +77,6 @@ export class Resonate {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
const url = buildForwardedURL(req);
|
|
80
|
-
console.log("URL", url);
|
|
81
80
|
const body: any = await req.json();
|
|
82
81
|
|
|
83
82
|
if (!req.body) {
|
|
@@ -192,10 +191,36 @@ export class Resonate {
|
|
|
192
191
|
}
|
|
193
192
|
|
|
194
193
|
function buildForwardedURL(req: Request) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
194
|
+
const headers = req.headers;
|
|
195
|
+
const url = new URL(req.url);
|
|
196
|
+
|
|
197
|
+
// 1. Hostname Logic
|
|
198
|
+
// Dev: "x-forwarded-host" is present (e.g., 127.0.0.1)
|
|
199
|
+
// Prod: "x-forwarded-host" is missing, so we use url.hostname (e.g., project.supabase.co)
|
|
200
|
+
const forwardedHost = headers.get("x-forwarded-host");
|
|
201
|
+
const host = forwardedHost ?? url.hostname;
|
|
202
|
+
|
|
203
|
+
// 2. Protocol Logic
|
|
204
|
+
// Always prefer "x-forwarded-proto" (usually https in prod), fallback to "http"
|
|
205
|
+
const proto = headers.get("x-forwarded-proto") ?? "http";
|
|
206
|
+
|
|
207
|
+
// 3. Port Logic
|
|
208
|
+
// Dev: We need the port (e.g., :54321).
|
|
209
|
+
// Prod: We rarely need :443 explicitly in the URL string.
|
|
210
|
+
const forwardedPort = headers.get("x-forwarded-port");
|
|
211
|
+
const port = (forwardedHost && forwardedPort) ? `:${forwardedPort}` : "";
|
|
212
|
+
|
|
213
|
+
// 4. Path Logic
|
|
214
|
+
// Dev: "x-forwarded-path" contains the full path (/functions/v1/hello-world)
|
|
215
|
+
// Prod: We must use url.pathname.
|
|
216
|
+
let path = headers.get("x-forwarded-path") ?? url.pathname;
|
|
217
|
+
|
|
218
|
+
// 5. Production Path Fix
|
|
219
|
+
// In Prod, the internal req.url often strips '/functions/v1'.
|
|
220
|
+
// We re-add it if we are in Prod (no forwardedHost) and it's missing.
|
|
221
|
+
if (!forwardedHost && !path.startsWith("/functions/v1")) {
|
|
222
|
+
path = `/functions/v1${path}`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return `${proto}://${host}${port}${path}`;
|
|
201
226
|
}
|