Skip to content

Commit 7f1f073

Browse files
committed
chore: use env
1 parent 0af6409 commit 7f1f073

4 files changed

Lines changed: 41 additions & 35 deletions

File tree

apps/api/src/index.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,32 @@ import { spaceRouter } from "./modules/space/route.js";
1212
import { itemRouter } from "./modules/item/route.js";
1313
import cron from "@elysiajs/cron";
1414
import { createDb } from "./drizzle/client.js";
15-
import {sql} from 'drizzle-orm'
15+
import { sql } from "drizzle-orm";
1616
import { uploadRouter } from "./modules/image/upload-multipart.js";
1717

1818
const db = createDb({ databaseUrl: process.env.DATABASE_URL });
1919

2020
const app = new Elysia()
21-
.use(betterAuthMiddleware)
22-
.use(cron({
23-
name: 'alphaRecalcQueueDelete',
24-
pattern: '0 */4 * * *',
25-
async run() {
26-
await db.execute(sql`DELETE FROM item_effective_recalc_queue WHERE enqueued_at < now() - interval '2 days';`)
27-
}
28-
}))
21+
.use(betterAuthMiddleware)
22+
.use(
23+
cron({
24+
name: "alphaRecalcQueueDelete",
25+
pattern: "0 */4 * * *",
26+
async run() {
27+
await db.execute(
28+
sql`DELETE FROM item_effective_recalc_queue WHERE enqueued_at < now() - interval '2 days';`
29+
);
30+
},
31+
})
32+
)
2933
.use(
3034
cors({
3135
origin: [
32-
"http://localhost:3000",
33-
"http://[::1]:3000",
34-
"http://localhost:5173",
35-
"http://localhost:5174",
36+
// "http://localhost:3000",
37+
// "http://[::1]:3000",
38+
// "http://localhost:5173",
39+
// "http://localhost:5174",
40+
`${process.env.ACCESS_CONTROL_ALLOW_ORIGIN!}:80`,
3641
],
3742
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
3843
credentials: true,
@@ -58,4 +63,4 @@ console.log(
5863
`🦊 Elysia is running at http://${app.server?.hostname}:${app.server?.port}`
5964
);
6065

61-
export type App = typeof app
66+
export type App = typeof app;

apps/api/src/modules/auth/route.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createAuthMiddleware, openAPI } from "better-auth/plugins";
66
import { createDb } from "../../drizzle/client.js";
77
import { authSchema, storageSchema } from "@repo/rdb/schema";
88

9-
const db = createDb({databaseUrl: process.env.DATABASE_URL,})
9+
const db = createDb({ databaseUrl: process.env.DATABASE_URL });
1010

1111
export const auth = betterAuth({
1212
databaseHooks: {
@@ -41,13 +41,13 @@ export const auth = betterAuth({
4141
itemType: "folder",
4242
})
4343
.returning();
44-
})
45-
}
46-
}
47-
}
44+
});
45+
},
46+
},
47+
},
4848
},
49-
baseURL: "http://localhost:3000/auth",
50-
trustedOrigins: ["http://localhost:3000", "http://[::1]:3000"],
49+
baseURL: `${process.env.ACCESS_CONTROL_ALLOW_ORIGIN!}:80/auth`,
50+
trustedOrigins: [`${process.env.ACCESS_CONTROL_ALLOW_ORIGIN!}:80`],
5151
advanced: {
5252
defaultCookieAttributes: {
5353
sameSite: "lax",
@@ -72,7 +72,7 @@ export const auth = betterAuth({
7272
{
7373
schema: authSchema,
7474
provider: "pg",
75-
debugLogs: true
75+
debugLogs: true,
7676
}
7777
),
7878
emailAndPassword: {
@@ -83,7 +83,7 @@ export const auth = betterAuth({
8383
enabled: true,
8484
clientId: process.env.GOOGLE_CLIENT_ID as string,
8585
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
86-
redirectURI: "http://localhost:20257/api/auth/callback/google",
86+
redirectURI: `${process.env.API_BASE_URL!}:20257/api/auth/callback/google`,
8787
accessType: "offline",
8888
prompt: "select_account",
8989
},
@@ -119,7 +119,7 @@ export const betterAuthMiddleware = new Elysia({ name: "better-auth" })
119119
.all("/api/auth/*", async (context: Context) => {
120120
if (["POST", "GET"].includes(context.request.method)) {
121121
const response = await auth.handler(context.request);
122-
122+
123123
console.log(response);
124124
// If it's a redirect response, make sure to return it properly
125125
if (response && response.status >= 300 && response.status < 400) {
@@ -171,4 +171,4 @@ export const betterAuthMiddleware = new Elysia({ name: "better-auth" })
171171
};
172172
},
173173
}),
174-
});
174+
});

packages/s3/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const {
99
SECRET_ACCESS_KEY,
1010
FORCE_PATH_STYLE,
1111
ACCESS_CONTROL_ALLOW_ORIGIN,
12-
PRE_SIGNED_URL_EXPIRE_IN, // in seconds
12+
PRE_SIGNED_URL_EXPIRE_IN,
13+
REDIS_URL, // in seconds
1314
} = Bun.env;
1415

1516
const requiredEnvVars = {
@@ -21,6 +22,7 @@ const requiredEnvVars = {
2122
FORCE_PATH_STYLE,
2223
ACCESS_CONTROL_ALLOW_ORIGIN,
2324
PRE_SIGNED_URL_EXPIRE_IN,
25+
REDIS_URL,
2426
};
2527

2628
for (const [key, value] of Object.entries(requiredEnvVars)) {
@@ -61,9 +63,9 @@ function createSTSClient(): STSClient {
6163

6264
export const accessControlAllowOrigin = ACCESS_CONTROL_ALLOW_ORIGIN as string;
6365
export const expiresIn = Number(PRE_SIGNED_URL_EXPIRE_IN);
64-
export const s3Bucket = S3_BUCKET as string
65-
export const s3Region = S3_REGION as string
66-
export const s3Endpoint = S3_ENDPOINT as string
66+
export const s3Bucket = S3_BUCKET as string;
67+
export const s3Region = S3_REGION as string;
68+
export const s3Endpoint = S3_ENDPOINT as string;
6769

6870
export const s3 = createS3Client();
6971
export const sts = createSTSClient();

packages/s3/src/worker-preview.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,18 @@ export type PreviewJob = {
5050
};
5151

5252
// Env
53-
const {
54-
REDIS_URL = "redis://127.0.0.1:6379",
55-
DATABASE_URL,
56-
S3_BUCKET,
57-
} = process.env as Record<string, string | undefined>;
53+
const { REDIS_URL, DATABASE_URL, S3_BUCKET } = process.env as Record<
54+
string,
55+
string | undefined
56+
>;
5857

5958
if (!DATABASE_URL) {
6059
throw new Error("DATABASE_URL is required for preview worker");
6160
}
6261

6362
// BullMQ workers use blocking Redis commands; ioredis must not retry requests.
6463
// See error: "BullMQ: Your redis options maxRetriesPerRequest must be null."
65-
const redis = new Redis(REDIS_URL, {
64+
const redis = new Redis(REDIS_URL!, {
6665
maxRetriesPerRequest: null,
6766
});
6867
export const PREVIEW_QUEUE_NAME = "preview.generate";

0 commit comments

Comments
 (0)