Skip to content

Commit cac2c7c

Browse files
committed
Add new CORS configuration related to preflight for android
1 parent f5ebd1a commit cac2c7c

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

backend/src/iac/backend-stack.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,30 @@ export class BackendStack extends cdk.Stack {
445445

446446
// Add CORS to all resources
447447
api.root.addCorsPreflight(corsOptions);
448-
apiResource.addCorsPreflight(corsOptions);
449-
reportsResource.addCorsPreflight(corsOptions);
450-
latestResource.addCorsPreflight(corsOptions);
451-
reportIdResource.addCorsPreflight(corsOptions);
452-
reportStatusResource.addCorsPreflight(corsOptions);
453-
docsResource.addCorsPreflight(corsOptions);
448+
apiResource.addCorsPreflight({
449+
...corsOptions,
450+
allowCredentials: false // This is crucial - make sure OPTIONS requests don't require credentials
451+
});
452+
reportsResource.addCorsPreflight({
453+
...corsOptions,
454+
allowCredentials: false
455+
});
456+
latestResource.addCorsPreflight({
457+
...corsOptions,
458+
allowCredentials: false
459+
});
460+
reportIdResource.addCorsPreflight({
461+
...corsOptions,
462+
allowCredentials: false
463+
});
464+
reportStatusResource.addCorsPreflight({
465+
...corsOptions,
466+
allowCredentials: false
467+
});
468+
docsResource.addCorsPreflight({
469+
...corsOptions,
470+
allowCredentials: false
471+
});
454472

455473
// Configure Gateway Responses to add CORS headers to error responses
456474
const gatewayResponseTypes = [
@@ -466,7 +484,7 @@ export class BackendStack extends cdk.Stack {
466484
apigateway.ResponseType.INTEGRATION_TIMEOUT,
467485
];
468486

469-
gatewayResponseTypes.forEach((responseType) => {
487+
gatewayResponseTypes.forEach(responseType => {
470488
new apigateway.CfnGatewayResponse(
471489
this,
472490
`${appName}GatewayResponse-${responseType.responseType.toString()}-${props.environment}`,

backend/src/main.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ async function bootstrap() {
1313
// Enable CORS
1414
app.enableCors({
1515
origin: [
16-
'*', // Vite default dev server
17-
],
16+
'http://localhost:5173',
17+
'http://localhost:3000',
18+
'http://localhost:4173',
19+
'https://localhost', // Add this for Capacitor
20+
...(process.env.FRONTEND_URL ? [process.env.FRONTEND_URL] : []),
21+
],
1822
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
1923
credentials: true,
2024
});

0 commit comments

Comments
 (0)