Skip to content

Commit 37e9195

Browse files
author
Andrea Aramini, INI-MBM-BNC (EXT)
committed
✨ feature(infrastructure): allow cors to cdn
1 parent 3983eb5 commit 37e9195

File tree

5 files changed

+9
-14
lines changed

5 files changed

+9
-14
lines changed

.env. development

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXT_PUBLIC_API_BASE_URL = "http://localhost:8080"

.env.production

-1
This file was deleted.

Dockerfile

+2-10
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@ WORKDIR /app
33
COPY package.json package-lock.json ./
44
RUN npm install --ignore-scripts
55

6-
FROM node:21.7.3-alpine AS builder
7-
WORKDIR /app
8-
COPY --from=deps /app/node_modules ./node_modules
9-
COPY . .
10-
RUN npm run build
116

127
FROM node:21.7.3-alpine AS production
138
WORKDIR /app
14-
ENV NODE_ENV production
159
COPY --from=deps /app/node_modules ./node_modules
16-
COPY --from=builder /app/.next ./.next
17-
COPY --from=builder /app/public ./public
18-
COPY --from=builder /app/package.json ./package.json
10+
COPY . .
1911
EXPOSE 3000
20-
ENTRYPOINT [ "npm", "run", "start"]
12+
ENTRYPOINT [ "npm", "run", "local"]

src/app/lib/client.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import axios from 'axios';
22

33
const instance = axios.create({
4-
baseURL: `${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1`,
4+
baseURL: process.env.NEXT_PUBLIC_API_BASE_URL
5+
? `${process.env.NEXT_PUBLIC_API_BASE_URL}/api/v1`
6+
: '/api/v1',
57
timeout: 10000,
68
headers: { 'Content-Type': 'application/json' },
79
});

stacks/Site.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ function createGateway(
4343
endpointType: apigateway.EndpointType.EDGE,
4444
securityPolicy: apigateway.SecurityPolicy.TLS_1_2,
4545
},
46-
//check if it is possible to add it later
46+
// not able to find any clean way to get cdn url, there is a circular dependency from gateway to cdn and viceversa
4747
defaultCorsPreflightOptions: {
48-
allowOrigins: [`https://${domainName}`],
48+
allowOrigins: [`https://${domainName}`, 'd1xsf9hqyfb7um.cloudfront.net'],
4949
allowMethods: apigateway.Cors.ALL_METHODS,
5050
allowHeaders: apigateway.Cors.DEFAULT_HEADERS,
5151
maxAge: cdk.Duration.days(1),
@@ -118,6 +118,7 @@ export function Site({ stack }) {
118118
cloudfront.addBehavior('/api/v1/*', new origins.RestApiOrigin(gateway), {
119119
allowedMethods: cf.AllowedMethods.ALLOW_ALL,
120120
viewerProtocolPolicy: cf.ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
121+
cachedMethods: cf.CachedMethods.CACHE_GET_HEAD_OPTIONS,
121122
cachePolicy: new cf.CachePolicy(stack, 'CachePolicy', {
122123
cachePolicyName: 'ApiBackend',
123124
maxTtl: cdk.Duration.seconds(0),

0 commit comments

Comments
 (0)