configure API proxy to EC2 origin in CDK stack and remove hardcoded backend URL from config
This commit is contained in:
parent
ec4f1ee6e9
commit
420df528a6
3 changed files with 36 additions and 1 deletions
5
fix.py
Normal file
5
fix.py
Normal 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
30
patch.diff
Normal 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: [
|
||||
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue