Skip to content

Commit d04021c

Browse files
authored
Merge pull request #53 from DokaIzk/feat/CORS-allow-list
Added CORS allow list
2 parents 69207f3 + 1e3c2d6 commit d04021c

5 files changed

Lines changed: 1595 additions & 1578 deletions

File tree

backend/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
PORT=3000
22
ALLOWED_ASSETS="USDC,XLM,ARS"
33

4+
# CORS allowed origins (comma-separated)
5+
CORS_ALLOWED_ORIGINS="http://localhost:5173"
6+
47
# Soroban RPC endpoint for event indexing
58
SOROBAN_RPC_URL=https://soroban-testnet.stellar.org:443
69
CONTRACT_ID=

backend/src/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import "dotenv/config";
22

3+
const parseOrigins = (originsStr: string): string[] => {
4+
return originsStr
5+
.split(",")
6+
.map((s) => s.trim())
7+
.filter(Boolean);
8+
};
9+
310
export const config = {
411
port: Number(process.env.PORT ?? 3001),
512
allowedAssets: (process.env.ALLOWED_ASSETS ?? "USDC,XLM")
613
.split(",")
714
.map((s) => s.trim().toUpperCase())
815
.filter(Boolean),
16+
corsAllowedOrigins: parseOrigins(
17+
process.env.CORS_ALLOWED_ORIGINS ?? "http://localhost:5173"
18+
),
919
};

backend/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ type CampaignListItem = ReturnType<typeof calculateProgress> extends infer Progr
4141
// Initialize DB
4242
initCampaignStore();
4343

44-
app.use(cors());
44+
app.use(
45+
cors({
46+
origin: config.corsAllowedOrigins,
47+
credentials: true,
48+
})
49+
);
4550
app.use(express.json());
4651

4752
// Request ID middleware

backend/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"forceConsistentCasingInFileNames": true,
1414
"resolveJsonModule": true,
1515
"declaration": true,
16-
"ignoreDeprecations": "6.0"
17-
},
16+
1817
"include": ["src/**/*"],
1918
"exclude": ["node_modules", "dist"]
2019
}

0 commit comments

Comments
 (0)