@teamscala/service-boot 0.23.548 → 0.23.550
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/package.json +1 -1
- package/src/auth-gate.ts +8 -22
package/package.json
CHANGED
package/src/auth-gate.ts
CHANGED
|
@@ -39,6 +39,7 @@ import * as v from "valibot";
|
|
|
39
39
|
import { configure as configureEventLog } from "@teamscala/event-log/configure";
|
|
40
40
|
import { getAppLogger } from "@teamscala/logger/app-loggers";
|
|
41
41
|
import type { Hono } from "hono";
|
|
42
|
+
import { proxy } from "hono/proxy";
|
|
42
43
|
|
|
43
44
|
import {
|
|
44
45
|
isStaticAssetPath,
|
|
@@ -140,29 +141,14 @@ export async function attachAuthGate(
|
|
|
140
141
|
try {
|
|
141
142
|
const headers = new Headers(c.req.raw.headers);
|
|
142
143
|
headers.set("host", new URL(otpBase).host);
|
|
143
|
-
const
|
|
144
|
-
method: c.req.method,
|
|
144
|
+
const res = await proxy(target, {
|
|
145
|
+
method: c.req.raw.method,
|
|
145
146
|
headers,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
const upstream = await fetch(target, init);
|
|
154
|
-
const resHeaders = new Headers(upstream.headers);
|
|
155
|
-
resHeaders.set("X-Auth-Forwarded", "scala-otp");
|
|
156
|
-
resHeaders.delete("Content-Encoding");
|
|
157
|
-
resHeaders.delete("Content-Length");
|
|
158
|
-
for (const sc of upstream.headers.getSetCookie()) {
|
|
159
|
-
resHeaders.append("Set-Cookie", sc);
|
|
160
|
-
}
|
|
161
|
-
return new Response(upstream.body, {
|
|
162
|
-
status: upstream.status,
|
|
163
|
-
statusText: upstream.statusText,
|
|
164
|
-
headers: resHeaders,
|
|
165
|
-
});
|
|
147
|
+
body: c.req.raw.body,
|
|
148
|
+
duplex: "half",
|
|
149
|
+
} as RequestInit);
|
|
150
|
+
res.headers.set("X-Auth-Forwarded", "scala-otp");
|
|
151
|
+
return res;
|
|
166
152
|
} catch (err) {
|
|
167
153
|
log.error(`[auth-forward] failed to reach scala-otp`, {
|
|
168
154
|
target,
|