Skip to content

Commit

Permalink
fix: näytä palvelun väliaikainen etusivu vain tuotannossa, jotta kehi…
Browse files Browse the repository at this point in the history
…tysympäristöissä pääsee näkemään oikean etusivun (#629)
  • Loading branch information
haapamakim authored Feb 22, 2023
1 parent 6468e4a commit d87a1a7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
14 changes: 14 additions & 0 deletions backend/test/lambdaAtEdge/frontendRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@ function runTest(uri: string, authenticated: boolean, expectedStatus: number | u
}

describe("frontendRequest lambda@edge", () => {
let originalEnv: string | undefined;

before(() => {
originalEnv = process.env.ENVIRONMENT;
});

after(function () {
process.env.ENVIRONMENT = originalEnv;
});

it("should return correct response for different paths", async () => {
process.env.ENVIRONMENT = "prod"; // etusivu vain tuotannnossa
runTest("/", false, 302, "/etusivu/index.html");
runTest("/something", false, 401);
runTest("/yllapito/kirjaudu", false, 401);
Expand All @@ -52,5 +63,8 @@ describe("frontendRequest lambda@edge", () => {
// Etusivu on auki kaikille
runTest("/etusivu", false, undefined);
runTest("/etusivu/index.html", false, undefined);

process.env.ENVIRONMENT = "dev"; // etusivu vain tuotannnossa
runTest("/", false, 401);
});
});
2 changes: 1 addition & 1 deletion common/kuntametadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("Metadata", () => {
expect(uud).to.eq("ely/ely01");
});

it.only("should render maakuntaoptions correctly", () => {
it("should render maakuntaoptions correctly", () => {
expect(
kuntametadata
.maakuntaOptions("fi")
Expand Down
1 change: 1 addition & 0 deletions deployment/lib/hassu-frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export class HassuFrontendStack extends Stack {
const functionCode = Fn.sub(sourceCode, {
BASIC_USERNAME: basicAuthenticationUsername,
BASIC_PASSWORD: basicAuthenticationPassword,
ENVIRONMENT: Config.env,
});
return new cloudfront.experimental.EdgeFunction(this, "frontendRequestFunction", {
runtime: Runtime.NODEJS_14_X,
Expand Down
3 changes: 2 additions & 1 deletion deployment/lib/lambda/frontendRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exports.handler = (event, context, callback) => {
// Configure authentication
var authUser = "${BASIC_USERNAME}";
var authPass = "${BASIC_PASSWORD}";
var environment = process.env.ENVIRONMENT || "${ENVIRONMENT}";

// varruct the Basic Auth string
var authString = "Basic " + b2a(authUser + ":" + authPass);
Expand All @@ -16,7 +17,7 @@ exports.handler = (event, context, callback) => {
// Continue request processing if authentication passed
callback(null, request);
} else {
if (request.uri === "/" || request.uri === "") {
if (environment === "prod" && (request.uri === "/" || request.uri === "")) {
// Ohjaa juuresta /etusivu:lle
callback(null, {
status: 302,
Expand Down

0 comments on commit d87a1a7

Please sign in to comment.