summaryrefslogtreecommitdiff
path: root/app/src/lib/server/s3.ts
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/lib/server/s3.ts')
-rw-r--r--app/src/lib/server/s3.ts14
1 files changed, 13 insertions, 1 deletions
diff --git a/app/src/lib/server/s3.ts b/app/src/lib/server/s3.ts
index a1a28fa..5d0dec9 100644
--- a/app/src/lib/server/s3.ts
+++ b/app/src/lib/server/s3.ts
@@ -1,7 +1,8 @@
import { S3Client } from "@aws-sdk/client-s3";
+import type { Handle } from "@sveltejs/kit";
// We would obviously read from .env in prod, but it's an annoying indirection for this demo.
-export function getS3Client(): S3Client {
+function getS3Client(): S3Client {
const client = new S3Client({
endpoint: "http://localhost:9000",
region: "us-east-1", // Required, but ignored for local usage.
@@ -14,3 +15,14 @@ export function getS3Client(): S3Client {
return client;
}
+
+export const s3Handle = (async ({ event, resolve }) => {
+ const s3Client = getS3Client();
+ event.locals.s3Client = s3Client;
+
+ try {
+ return await resolve(event);
+ } finally {
+ s3Client.destroy();
+ }
+}) satisfies Handle;