Skip to content

Commit 2965558

Browse files
authored
Setup IaC for staging environment (#1059)
* vercel function oidc * use vercel oidc * make aws endpoint optional * handle VERCEL_AWS_ROLE_ARN * use get range=0-0 instead of head * optional secret keys * stanging env vars * format
1 parent 64bf989 commit 2965558

File tree

10 files changed

+180
-190
lines changed

10 files changed

+180
-190
lines changed

apps/web/app/s/[videoId]/_components/CapVideoPlayer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ export function CapVideoPlayer({
8888
? `${videoSrc}&_t=${timestamp}`
8989
: `${videoSrc}?_t=${timestamp}`;
9090

91-
const response = await fetch(urlWithTimestamp, { method: "HEAD" });
91+
const response = await fetch(urlWithTimestamp, {
92+
method: "GET",
93+
headers: { range: "bytes=0-0" },
94+
});
9295
const finalUrl = response.redirected ? response.url : urlWithTimestamp;
9396

9497
// Check if the resolved URL is from a CORS-incompatible service

apps/web/lib/transcribe.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ export async function transcribeVideo(
8080

8181
// Check if video file actually exists before transcribing
8282
try {
83-
const headResponse = await fetch(videoUrl, { method: "HEAD" });
83+
const headResponse = await fetch(videoUrl, {
84+
method: "GET",
85+
headers: { range: "bytes=0-0" },
86+
});
8487
if (!headResponse.ok) {
8588
// Video not ready yet - reset to null for retry
8689
await db()

apps/web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"@tanstack/react-store": "^0.7.7",
6969
"@ts-rest/core": "^3.52.1",
7070
"@uidotdev/usehooks": "^2.4.1",
71+
"@vercel/functions": "^3.1.0",
7172
"@virtual-grid/react": "^2.0.3",
7273
"@workos-inc/node": "^7.34.0",
7374
"aws-sdk": "^2.1530.0",

apps/web/utils/s3.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import type {
4040
RequestPresigningArguments,
4141
StreamingBlobPayloadInputTypes,
4242
} from "@smithy/types";
43+
import { awsCredentialsProvider } from "@vercel/functions/oidc";
4344
import type { InferSelectModel } from "drizzle-orm";
4445

4546
type S3Config = {
@@ -64,16 +65,19 @@ async function tryDecrypt(
6465

6566
export async function getS3Config(config?: S3Config, internal = false) {
6667
if (!config) {
68+
const env = serverEnv();
6769
return {
6870
endpoint: internal
69-
? (serverEnv().S3_INTERNAL_ENDPOINT ?? serverEnv().CAP_AWS_ENDPOINT)
70-
: (serverEnv().S3_PUBLIC_ENDPOINT ?? serverEnv().CAP_AWS_ENDPOINT),
71-
region: serverEnv().CAP_AWS_REGION,
72-
credentials: {
73-
accessKeyId: serverEnv().CAP_AWS_ACCESS_KEY ?? "",
74-
secretAccessKey: serverEnv().CAP_AWS_SECRET_KEY ?? "",
75-
},
76-
forcePathStyle: serverEnv().S3_PATH_STYLE,
71+
? (env.S3_INTERNAL_ENDPOINT ?? env.CAP_AWS_ENDPOINT)
72+
: (env.S3_PUBLIC_ENDPOINT ?? env.CAP_AWS_ENDPOINT),
73+
region: env.CAP_AWS_REGION,
74+
credentials: env.VERCEL_AWS_ROLE_ARN
75+
? awsCredentialsProvider({ roleArn: env.VERCEL_AWS_ROLE_ARN })
76+
: {
77+
accessKeyId: env.CAP_AWS_ACCESS_KEY ?? "",
78+
secretAccessKey: env.CAP_AWS_SECRET_KEY ?? "",
79+
},
80+
forcePathStyle: env.S3_PATH_STYLE,
7781
};
7882
}
7983

infra/sst-env.d.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@
55

66
declare module "sst" {
77
export interface Resource {
8-
DISCORD_BOT_TOKEN: {
9-
type: "sst.sst.Secret";
10-
value: string;
11-
};
12-
DiscordBotScript: {
13-
type: "sst.cloudflare.Worker";
14-
};
15-
GITHUB_APP_PRIVATE_KEY: {
8+
DATABASE_URL: {
169
type: "sst.sst.Secret";
1710
value: string;
1811
};

0 commit comments

Comments
 (0)