-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(django-vue): add construct for app with both django and vue depl…
…oyed to the same domain using cloudformation wip
- Loading branch information
1 parent
a51a2be
commit 32b74e5
Showing
7 changed files
with
262 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* | ||
* This is a high-level construct that demonstrates | ||
* how to use the static site CloudFrontWebDistribution | ||
* together with the ECS Stack. | ||
* | ||
* CloudFront allows for both the static site and | ||
* the `/api` calls to be served from the same | ||
* domain (app.example.com, for example). | ||
* | ||
* This would be a good setup if you are using a Vue or React | ||
* static website (such as an SPA) and your Django app's | ||
* REST API uses either JWT (with HttpOnly refresh token) | ||
* or Session-based API authentication. | ||
* | ||
* If you are using a Vue app and a Django app and don't mind | ||
* storing JWT on the browser's localStorage, you can also use this | ||
* approach, but you can also setup the frontend and backend on | ||
* different domains. | ||
* | ||
**/ | ||
|
||
import * as cdk from '@aws-cdk/core'; | ||
import { DjangoEcs } from './index'; | ||
import { StaticSite } from './index'; | ||
import * as acm from '@aws-cdk/aws-certificatemanager'; | ||
import * as route53 from '@aws-cdk/aws-route53'; | ||
|
||
/** | ||
* Django and Vue application stack props | ||
*/ | ||
export interface DjangoVueProps { | ||
/** | ||
* Certificate ARN for looking up the Certificate to use for CloudFront and ALB | ||
*/ | ||
readonly certificateArn?: string; | ||
|
||
readonly domainName: string; | ||
|
||
readonly zoneName: string; | ||
|
||
|
||
} | ||
|
||
/** | ||
* | ||
* Construct for projects using Django backend and static site for frontend | ||
*/ | ||
export class DjangoVue extends cdk.Construct { | ||
constructor(scope: cdk.Construct, id: string, props: DjangoVueProps) { | ||
super(scope, id); | ||
|
||
let certificate; | ||
if (props.certificateArn) { | ||
certificate = acm.Certificate.fromCertificateArn(scope, 'Cert', process.env.CERTIFICATE_ARN!); | ||
} else { | ||
certificate = new acm.DnsValidatedCertificate(scope, 'Cert', { | ||
domainName: props.domainName, | ||
hostedZone: route53.HostedZone.fromLookup(scope, 'HostedZone', { | ||
domainName: props.zoneName, | ||
}) | ||
}) | ||
} | ||
|
||
// const apiBackend = | ||
const apiBackend = new DjangoEcs(scope, 'DjangoEcsSample', { | ||
imageDirectory: './test/django-step-by-step/backend', | ||
webCommand: ['./scripts/start_prod.sh'], | ||
useCeleryBeat: true, | ||
apiDomainName: process.env.API_DOMAIN_NAME, | ||
zoneName: process.env.ZONE_NAME, | ||
useEcsExec: true, | ||
frontendUrl: process.env.FRONTEND_URL, | ||
certificateArn: certificate.certificateArn, | ||
}); | ||
|
||
new StaticSite(scope, 'StaticSiteSample', { | ||
frontendDomainName: props.domainName, | ||
pathToDist: 'test/django-step-by-step/quasar-app/dist/pwa', | ||
zoneName: props.zoneName, | ||
loadBalancer: apiBackend.loadBalancer, | ||
// assetsBucket: apiBackend.staticFileBucket, | ||
}); | ||
|
||
new cdk.CfnOutput(this, 'loadBalancerName', { value: apiBackend.loadBalancer.loadBalancerDnsName }); | ||
|
||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './django-ecs'; | ||
export * from './django-eks'; | ||
export * from './django-s3-storage'; | ||
export * from './static-site'; | ||
export * from './static-site'; | ||
export * from './django-vue'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import { DjangoVue } from '../index'; | ||
|
||
const env = { | ||
region: process.env.AWS_DEFAULT_REGION || 'us-east-1', | ||
account: process.env.AWS_ACCOUNT_ID, | ||
}; | ||
|
||
|
||
const app = new cdk.App(); | ||
const stack = new cdk.Stack(app, 'DjangoVueStack', { env }); | ||
|
||
// no props needed on this construct | ||
const construct = new DjangoVue(stack, 'DjangoVueSample', { | ||
domainName: process.env.FRONTEND_DOMAIN_NAME!, | ||
zoneName: process.env.ZONE_NAME!, | ||
}); | ||
|
||
/** | ||
* Add tagging for this construct and all child constructs | ||
*/ | ||
cdk.Tags.of(construct).add('stack', 'DjangoVueStack'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters