Skip to content

Commit

Permalink
fix: Korjaa ilmoitustaulusyötteen tunnistautuminen (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
haapamakim committed Jun 22, 2022
1 parent b5fb35c commit 9c92143
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 13 additions & 2 deletions deployment/lib/hassu-frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
OriginRequestPolicy,
OriginSslPolicy,
PriceClass,
ViewerProtocolPolicy
ViewerProtocolPolicy,
} from "@aws-cdk/aws-cloudfront";
import { Config } from "./config";
import { HttpOrigin } from "@aws-cdk/aws-cloudfront-origins/lib/http-origin";
Expand All @@ -28,7 +28,7 @@ import {
PolicyDocument,
PolicyStatement,
Role,
ServicePrincipal
ServicePrincipal,
} from "@aws-cdk/aws-iam";
import * as fs from "fs";
import { EdgeFunction } from "@aws-cdk/aws-cloudfront/lib/experimental";
Expand Down Expand Up @@ -152,6 +152,7 @@ export class HassuFrontendStack extends cdk.Stack {
invalidationPaths: ["/*"],
});
this.configureNextJSAWSPermissions(nextJSLambdaEdge);
HassuFrontendStack.configureNextJSRequestHeaders(nextJSLambdaEdge);

const distribution: cloudfront.Distribution = nextJSLambdaEdge.distribution;
new cdk.CfnOutput(this, "CloudfrontPrivateDNSName", {
Expand All @@ -176,6 +177,16 @@ export class HassuFrontendStack extends cdk.Stack {
this.props.internalBucket.grantReadWrite(nextJSLambdaEdge.edgeLambdaRole);
}

private static configureNextJSRequestHeaders(nextJSLambdaEdge: NextJSLambdaEdge) {
// Enable forwarding the headers to the nextjs API lambda to get the authorization header
const additionalBehaviors = (nextJSLambdaEdge.distribution as any).additionalBehaviors;
for (const additionalBehavior of additionalBehaviors) {
if (additionalBehavior.props.pathPattern == "api/*") {
additionalBehavior.props.originRequestPolicy = OriginRequestPolicy.ALL_VIEWER;
}
}
}

private createFrontendRequestFunction(
env: string,
basicAuthenticationUsername: string,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@
"log:dynamodb-stream-handler": "aws logs tail --follow --since 1h /aws/lambda/hassu-dynamodb-stream-handler-$ENVIRONMENT",
"log:dynamodb-stream-handler:dev": "aws logs tail --follow --since 1h /aws/lambda/hassu-dynamodb-stream-handler-dev",
"log:email": "aws logs tail --follow --since 1h /aws/lambda/hassu-email-$ENVIRONMENT",
"log:frontend:nextjsapi": "cross-env AWS_REGION=eu-central-1 aws logs tail --follow --since 1h /aws/lambda/us-east-1.NextJsApp-${ENVIRONMENT}ApiV2",
"log:frontend:nextjsapi:dev": "cross-env AWS_REGION=eu-central-1 aws logs tail --follow --since 1h /aws/lambda/us-east-1.NextJsApp-devApiV2",
"sonar": "node -r dotenv/config ./deployment/bin/sonar.js dotenv_config_path=.env.local",
"opensearch:getmapping": "cross-env DOTENV_CONFIG_PATH=.env.test ts-node --project=backend/tsconfig.json -r dotenv/config ./deployment/bin/opensearch.ts getmapping projekti backend/src/projektiSearch/projekti-mapping.json",
"opensearch:getsettings": "cross-env DOTENV_CONFIG_PATH=.env.test ts-node --project=backend/tsconfig.json -r dotenv/config ./deployment/bin/opensearch.ts getsettings projekti backend/src/projektiSearch/projekti-settings.json",
Expand Down

0 comments on commit 9c92143

Please sign in to comment.