Skip to content

Commit

Permalink
Check authorization key
Browse files Browse the repository at this point in the history
  • Loading branch information
mbenedettini committed Sep 23, 2024
1 parent c9ace27 commit e9a8188
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ router.get("/", (ctx: oak.Context) => {
};
});

function checkAuthorization(ctx: oak.Context) {
const authorizationKey = Deno.env.get("AUTHORIZATION_KEY");
if (Boolean(authorizationKey) && ctx.request.headers.get("Authorization") !== authorizationKey) {
ctx.response.status = 401;
return false;
}
return true;
}

router.post("/html2pdf", async (ctx: oak.Context) => {
if (!ctx.request.hasBody) {
return;
}
const authorizationKey = Deno.env.get("AUTHORIZATION_KEY");
if (Boolean(authorizationKey) && ctx.request.headers.get("Authorization") !== authorizationKey) {
ctx.response.status = 401;
if (!checkAuthorization(ctx)) {
return;
}

Expand All @@ -30,6 +36,10 @@ router.post("/html2pdf", async (ctx: oak.Context) => {
});

router.post("/html2pdf:json", async (ctx: oak.Context) => {
if (!checkAuthorization(ctx)) {
return;
}

const body = ctx.request.body;

if (body.type() !== "json") {
Expand Down

0 comments on commit e9a8188

Please sign in to comment.