Skip to content

Commit

Permalink
minor: cloudfront redirect to latitude.so from ai.latitude.so
Browse files Browse the repository at this point in the history
  • Loading branch information
geclos committed Sep 14, 2024
1 parent be39ee0 commit a381676
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
94 changes: 94 additions & 0 deletions apps/infra/src/core/cloudfront.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import * as aws from '@pulumi/aws'

const certificate = new aws.acm.Certificate(
'latitudeCertificate',
{
domainName: 'ai.latitude.so',
validationMethod: 'DNS',
},
{ provider: new aws.Provider('us-east-1', { region: 'us-east-1' }) },
)

const redirectFunction = new aws.cloudfront.Function('redirectFunction', {
code: `
function handler(event) {
var response = {
statusCode: 301,
statusDescription: 'Moved Permanently',
headers: {
'location': { value: 'https://latitude.so' + event.request.uri }
}
};
return response;
}
`,
name: 'redirect-to-latitude',
runtime: 'cloudfront-js-1.0',
})

const distribution = new aws.cloudfront.Distribution('latitudeRedirect', {
enabled: true,
isIpv6Enabled: true,
httpVersion: 'http2',
aliases: ['ai.latitude.so'],
defaultCacheBehavior: {
allowedMethods: ['GET', 'HEAD'],
cachedMethods: ['GET', 'HEAD'],
targetOriginId: 'latitudeOrigin',
forwardedValues: {
queryString: false,
cookies: {
forward: 'none',
},
},
viewerProtocolPolicy: 'redirect-to-https',
minTtl: 0,
defaultTtl: 300,
maxTtl: 1200,
functionAssociations: [
{
eventType: 'viewer-request',
functionArn: redirectFunction.arn,
},
],
},
origins: [
{
domainName: 'latitude.so',
originId: 'latitudeOrigin',
customOriginConfig: {
httpPort: 80,
httpsPort: 443,
originSslProtocols: ['TLSv1.2'],
originProtocolPolicy: 'https-only',
},
},
],
restrictions: {
geoRestriction: {
restrictionType: 'none',
},
},
viewerCertificate: {
acmCertificateArn: certificate.arn,
sslSupportMethod: 'sni-only',
minimumProtocolVersion: 'TLSv1.2_2021',
},
})

export const distributionUrl = distribution.domainName

const record = new aws.route53.Record('latitudeRecord', {
zoneId: 'Z04918046RTZRA6UX0HY',
name: 'ai.latitude.so',
type: 'A',
aliases: [
{
name: distribution.domainName,
zoneId: distribution.hostedZoneId,
evaluateTargetHealth: false,
},
],
})

export const recordName = record.name
1 change: 1 addition & 0 deletions apps/infra/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './ecs'
export * from './iam'
export * from './s3'
export * from './secrets'
export * from './cloudfront'

0 comments on commit a381676

Please sign in to comment.