| 1 | #!/usr/bin/env bash |
| 2 | # run-dev.sh — build and run Slides locally, with no setup at all. |
| 3 | # |
| 4 | # scripts/run-dev.sh # http://localhost:8091 |
| 5 | # SLIDES_DEV_PORT=9000 scripts/run-dev.sh |
| 6 | # |
| 7 | # It runs with -env development, which is the ONLY way that env can be |
| 8 | # selected (cmd/slides/main.go's chooseEnv refuses to honour it from |
| 9 | # $SLIDES_ENV, so a deployment's env-var block can never reach this |
| 10 | # mode). In development, and nowhere else, four settings default: |
| 11 | # |
| 12 | # * the instance key becomes a fixed, public string; |
| 13 | # * mail is written to this terminal instead of being sent, so the |
| 14 | # magic link is the line marked "magic links will be logged"; |
| 15 | # * the allowlist admits every address; |
| 16 | # * the object store is a directory beside the scratch database. |
| 17 | # |
| 18 | # Sign in by entering any address at http://localhost:8091/signin, then |
| 19 | # copying the /auth/verify?token=... link out of the log below into the |
| 20 | # browser. |
| 21 | # |
| 22 | # The database is a scratch file under $TMPDIR, thrown away with it: |
| 23 | # nothing this script runs should ever be pointed at data that matters. |
| 24 | set -euo pipefail |
| 25 | |
| 26 | cd "$(dirname "$0")/.." |
| 27 | |
| 28 | port="${SLIDES_DEV_PORT:-8091}" |
| 29 | tmp="${TMPDIR:-/tmp}" |
| 30 | state="${tmp%/}/slides-dev" |
| 31 | mkdir -p "$state" |
| 32 | |
| 33 | # CGO_ENABLED=0 here as everywhere: the stack is cgo-free by design, and |
| 34 | # a local build that quietly used cgo would not be the binary CI checks. |
| 35 | CGO_ENABLED=0 go build -o "$state/slides" ./cmd/slides |
| 36 | |
| 37 | echo "slides: http://localhost:$port (database: $state/slides.db)" |
| 38 | echo "slides: sign in at http://localhost:$port/signin — the magic link is logged below" |
| 39 | |
| 40 | # -addr is what main.go derives the origin from when $SLIDES_ORIGIN is |
| 41 | # unset, and it has to be the host a browser will actually send back as |
| 42 | # its own Origin header — hence localhost, not a bare :port. |
| 43 | exec "$state/slides" \ |
| 44 | -env development \ |
| 45 | -addr "localhost:$port" \ |
| 46 | -db "$state/slides.db" |
| 47 | |