@remit/backend 0.0.38 → 0.0.39
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/index.ts +31 -25
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { inspect } from "node:util";
|
|
5
|
-
import { logger, withTelemetry } from "@remit/logger-lambda";
|
|
5
|
+
import { logger, withLogContext, withTelemetry } from "@remit/logger-lambda";
|
|
6
6
|
import type { APIGatewayProxyEvent, Context } from "aws-lambda";
|
|
7
7
|
import {
|
|
8
8
|
type Document,
|
|
@@ -141,30 +141,36 @@ const readOriginHeader = (
|
|
|
141
141
|
return undefined;
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
144
|
+
// A scope, not `logger.setBindings`: this process serves requests concurrently,
|
|
145
|
+
// and bindings on the shared logger belong to whichever request wrote them last,
|
|
146
|
+
// so a line gets attributed to the wrong request. The scope follows the request
|
|
147
|
+
// through its own async continuations and nothing else.
|
|
148
|
+
const rawHandler = async (event: APIGatewayProxyEvent, context: Context) =>
|
|
149
|
+
withLogContext(
|
|
150
|
+
{
|
|
151
|
+
requestId: context.awsRequestId,
|
|
152
|
+
path: event.path,
|
|
153
|
+
method: event.httpMethod,
|
|
154
|
+
},
|
|
155
|
+
async () => {
|
|
156
|
+
logger.debug(
|
|
157
|
+
{ method: event.httpMethod, path: event.path },
|
|
158
|
+
"Request received",
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const origin = readOriginHeader(event.headers);
|
|
162
|
+
|
|
163
|
+
if (usesBetterAuthJwt()) {
|
|
164
|
+
const denied = await authenticatePostgresRequest(event);
|
|
165
|
+
if (denied) return denied;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return runWithRequestContext({ origin }, () =>
|
|
169
|
+
api
|
|
170
|
+
.handleRequest(normalizeRequest(event), event, context)
|
|
171
|
+
.catch(handleError),
|
|
172
|
+
);
|
|
173
|
+
},
|
|
167
174
|
);
|
|
168
|
-
};
|
|
169
175
|
|
|
170
176
|
export const handler = withTelemetry(rawHandler);
|