From 420df528a6d23446cff0dc19d050099239464065 Mon Sep 17 00:00:00 2001 From: vickytechkey Date: Sat, 5 Sep 2026 15:39:52 +0530 Subject: [PATCH] configure API proxy to EC2 origin in CDK stack and remove hardcoded backend URL from config --- fix.py | 5 +++++ patch.diff | 30 ++++++++++++++++++++++++++++++ src/config.ts | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 fix.py create mode 100644 patch.diff diff --git a/fix.py b/fix.py new file mode 100644 index 0000000..1f80a3b --- /dev/null +++ b/fix.py @@ -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) diff --git a/patch.diff b/patch.diff new file mode 100644 index 0000000..acbc42f --- /dev/null +++ b/patch.diff @@ -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: [ diff --git a/src/config.ts b/src/config.ts index 0d00c46..cbdfe85 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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 = {