Skip to content

Commit 025756d

Browse files
Merge pull request #35 from Dnreikronos/fix/cors
CORS CONFIG
2 parents d9f44b9 + 597705b commit 025756d

4 files changed

Lines changed: 32 additions & 24 deletions

File tree

backend/.gitignore

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,8 @@ CLAUDE.md
88
# Test coverage
99
coverage
1010

11-
# TypeScript build output (compiled files alongside source)
12-
src/**/*.js
13-
src/**/*.js.map
14-
src/**/*.d.ts
15-
src/**/*.d.ts.map
16-
*.d.ts.map
11+
# TypeScript build output
12+
build/
1713

18-
# Root level build files
19-
/*.js
20-
/*.d.ts
21-
22-
# But keep source type definitions
23-
!src/types/**/*.d.ts
14+
# Keep source type definitions
15+
!src/types/**/*.d.ts

backend/src/config.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const envSchema = z.object({
1414
.enum(["development", "production", "test"])
1515
.default("development"),
1616
PORT: z.string().default("3001"),
17-
FRONTEND_URL: z.url("FRONTEND_URL must be a valid URL"),
17+
FRONTEND_URL: z.string().min(1, "FRONTEND_URL is required"),
1818
SOLANA_NETWORK: z.enum(["mainnet", "devnet"]).default("mainnet"),
1919
});
2020

@@ -34,4 +34,14 @@ const parseEnv = () => {
3434
}
3535
};
3636

37-
export const config = parseEnv();
37+
const rawConfig = parseEnv();
38+
39+
// Parse CORS origins from comma-separated FRONTEND_URL
40+
const corsOrigins = rawConfig.FRONTEND_URL.split(",")
41+
.map((url) => url.trim())
42+
.filter(Boolean);
43+
44+
export const config = {
45+
...rawConfig,
46+
CORS_ORIGINS: corsOrigins,
47+
};

backend/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ const buildServer = async () => {
5353
});
5454

5555
await fastify.register(fastifyCors, {
56-
origin: config.FRONTEND_URL,
56+
origin:
57+
config.CORS_ORIGINS.length === 1
58+
? config.CORS_ORIGINS[0]!
59+
: config.CORS_ORIGINS,
5760
credentials: true,
61+
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
62+
allowedHeaders: ["Content-Type", "Authorization"],
5863
});
5964

6065
await fastify.register(fastifyJwt, {
@@ -79,7 +84,9 @@ const buildServer = async () => {
7984
await fastify.register(authRoutes, { prefix: "/api/auth" });
8085
await fastify.register(planRoutes, { prefix: "/api/links" });
8186
await fastify.register(payerRoutes, { prefix: "/api/payers" });
82-
await fastify.register(paymentExecutionRoutes, { prefix: "/api/payment-executions" });
87+
await fastify.register(paymentExecutionRoutes, {
88+
prefix: "/api/payment-executions",
89+
});
8390
await fastify.register(subscribeRoutes, { prefix: "/api/subscribe" });
8491
await fastify.register(subscriptionRoutes, { prefix: "/api/subscriptions" });
8592

backend/tsconfig.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
{
22
// Visit https://aka.ms/tsconfig to read more about this file
3+
"include": ["src/**/*"],
4+
"exclude": ["node_modules", "build", "**/*.test.ts", "**/*.spec.ts"],
35
"compilerOptions": {
46
// File Layout
5-
// "rootDir": "./src",
6-
// "outDir": "./dist",
7+
"rootDir": "./src",
8+
"outDir": "./build",
79

810
// Environment Settings
911
// See also https://aka.ms/tsconfig/module
1012
"module": "nodenext",
13+
"moduleResolution": "nodenext",
1114
"target": "esnext",
12-
"types": [],
13-
// For nodejs:
14-
// "lib": ["esnext"],
15-
// "types": ["node"],
16-
// and npm install -D @types/node
15+
"lib": ["esnext"],
1716

1817
// Other Outputs
1918
"sourceMap": true,
@@ -39,6 +38,6 @@
3938
"isolatedModules": true,
4039
"noUncheckedSideEffectImports": true,
4140
"moduleDetection": "force",
42-
"skipLibCheck": true,
41+
"skipLibCheck": true
4342
}
4443
}

0 commit comments

Comments
 (0)