Skip to content

Commit a701810

Browse files
committed
fix: inject turnstile sitekey into website during build
Requires the CF_SITEKEY environment variable
1 parent ee4e37c commit a701810

6 files changed

Lines changed: 22 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vscode
22
**/secrets/**
33
.env
4+
env.hcl

compose.dev.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
services:
22
biixie_frontend:
3+
pull_policy: never
34
restart: no
45
biixie_backend:
6+
pull_policy: never
57
restart: no
68
environment:
79
DEBUG: true

docker-bake.hcl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
variable "CF_SITEKEY" {
2+
default = "$CF_SITEKEY"
3+
4+
validation {
5+
condition = CF_SITEKEY != ""
6+
error_message = "CF_SITEKEY environment variable not set"
7+
}
8+
}
9+
110
group "default" {
211
targets = [ "frontend", "backend" ]
312
}
@@ -6,6 +15,10 @@ target "frontend" {
615
tags = [ "biixie/biixie.com:frontend-latest" ]
716
content = "."
817
dockerfile = "frontend/Dockerfile"
18+
19+
args = {
20+
CF_SITEKEY = CF_SITEKEY
21+
}
922
}
1023

1124
target "backend" {

frontend/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ RUN --mount=type=secret,id=GRAPHQL_GITHUB_API_TOKEN,env=GITHUB_TOKEN \
2525
RUN cat ./projects.json
2626

2727
# Build website
28+
ARG CF_SITEKEY # Used to inject the Turnstile sitekey into the site.
29+
ENV CF_SITEKEY=$CF_SITEKEY
2830
RUN zola build
2931

3032
# Serve the built website.

frontend/static/js/turnstile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ let cfResponseToken = null;
22

33
function verifyAction(action) {
44
if (cfResponseToken == null) {
5+
let cfSiteKey = document.documentElement.getAttribute("data-cf-sitekey");
6+
57
// Turnstile has not yet rendered.
68
let turnstileDialog = document.getElementById("cf-turnstile-dialog");
79
turnstileDialog.showModal();
810

911
turnstile.render("#cf-turnstile-widget", {
10-
sitekey: "0x4AAAAAAA5Z7Cr4D0kvesdz",
12+
sitekey: cfSiteKey,
1113
callback: async function(token) {
1214
cfResponseToken = token;
1315

frontend/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!DOCTYPE html>
22
<!-- force dark-mode on non-JS visitors cus why not >:3 -->
3-
<html lang="en" data-theme="dark">
3+
<html lang="en" data-theme="dark" data-cf-sitekey={{ get_env(name="CF_SITEKEY" ) }}>
44
<head>
55
<!-- This looks awful -->
66
{% if section.title %}

0 commit comments

Comments
 (0)