Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
static-site: switch edge to take injections instead of arns
Browse files Browse the repository at this point in the history
  • Loading branch information
fwang committed Sep 11, 2024
1 parent 01f2b0a commit cd833d8
Show file tree
Hide file tree
Showing 2 changed files with 210 additions and 138 deletions.
33 changes: 13 additions & 20 deletions examples/aws-static-site-basic-auth/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,21 @@ export default $config({
Buffer.from(`${username}:${password}`).toString("base64")
);

const fn = new aws.cloudfront.Function("BasicAuth", {
runtime: "cloudfront-js-2.0",
code: $interpolate`
function handler(event) {
if (!event.request.headers.authorization || event.request.headers.authorization.value !== "Basic ${basicAuth}") {
return {
statusCode: 401,
headers: {
"www-authenticate": { value: "Basic" }
}
};
}
return event.request;
}`,
});

new sst.aws.StaticSite("MySite", {
path: "site",
// Don't password protect prod
edge: $app.stage !== "production"
? { viewerRequest: fn.arn }
: undefined,
edge: {
viewerRequest: {
injection: $interpolate`
if (!event.request.headers.authorization || event.request.headers.authorization.value !== "Basic ${basicAuth}") {
return {
statusCode: 401,
headers: {
"www-authenticate": { value: "Basic" }
}
};
}`,
},
},
});
},
});
Loading

0 comments on commit cd833d8

Please sign in to comment.