configure API proxy to EC2 origin in CDK stack and remove hardcoded backend URL from config
All checks were successful
Beta CI/CD Pipeline / build-and-test (push) Successful in 58s
Beta CI/CD Pipeline / deploy-beta (push) Successful in 12s

This commit is contained in:
vickytechkey 2026-09-05 15:39:52 +05:30
parent ec4f1ee6e9
commit 420df528a6
3 changed files with 36 additions and 1 deletions

5
fix.py Normal file
View file

@ -0,0 +1,5 @@
with open('/home/vignesh/github/Tiproemail/aws_cdk/lib/betasupplier-site-stack.ts', 'r') as f:
content = f.read()
content = content.replace(' }\n errorResponses: [', ' },\n errorResponses: [')
with open('/home/vignesh/github/Tiproemail/aws_cdk/lib/betasupplier-site-stack.ts', 'w') as f:
f.write(content)

30
patch.diff Normal file
View file

@ -0,0 +1,30 @@
--- /home/vignesh/github/Tiproemail/aws_cdk/lib/betasupplier-site-stack.ts
+++ /home/vignesh/github/Tiproemail/aws_cdk/lib/betasupplier-site-stack.ts
@@ -19,13 +19,25 @@
+ const ec2Origin = new origins.HttpOrigin('ec2-16-113-57-127.ap-south-2.compute.amazonaws.com', {
+ protocolPolicy: cloudfront.OriginProtocolPolicy.HTTPS_ONLY,
+ });
+
// 2. Create CloudFront Distribution
// origins.S3Origin will automatically create an Origin Access Identity (OAI)
// and update the S3 bucket policy to allow access only from this CloudFront distribution.
const distribution = new cloudfront.Distribution(this, 'BetaSupplierSiteDistribution', {
defaultRootObject: 'index.html',
defaultBehavior: {
origin: new origins.S3Origin(websiteBucket),
viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD,
cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD,
cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED,
},
+ additionalBehaviors: {
+ '/api/*': {
+ origin: ec2Origin,
+ viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
+ allowedMethods: cloudfront.AllowedMethods.ALLOW_ALL,
+ cachePolicy: cloudfront.CachePolicy.CACHING_DISABLED,
+ originRequestPolicy: cloudfront.OriginRequestPolicy.ALL_VIEWER,
+ }
+ },
errorResponses: [

View file

@ -2,7 +2,7 @@ const getApiBaseUrl = () => {
if (import.meta.env.DEV) {
return 'http://127.0.0.1:8000';
}
return 'https://ec2-16-113-57-127.ap-south-2.compute.amazonaws.com';
return '';
};
export const CONFIG = {