booleanbeyond/jobfetch
0
1#!/usr/bin/env bash2# Build the static front end for Vercel.3#4# The UI is a single self-contained file. All this does is copy it to `dist/`5# and stamp the API origin into the `jobfetch-api-base` meta tag, so the page6# knows where the scraper lives when the two are hosted separately.7#8# Set API_BASE in the Vercel project's environment variables, e.g.9# API_BASE=https://jobfetch.onrender.com10#11# Leaving it unset produces a same-origin build, which is only useful if you12# also proxy /api to the scraper — so we fail loudly instead of shipping a UI13# whose every request 404s against Vercel's static host.14set -euo pipefail15 16SRC="static/index.html"17OUT="dist"18 19if [[ ! -f "$SRC" ]]; then20 echo "build-vercel: $SRC not found (run from the repo root)" >&221 exit 122fi23 24if [[ -z "${API_BASE:-}" ]]; then25 echo "build-vercel: API_BASE is not set." >&226 echo " The scraper cannot run on Vercel (it needs Chromium), so the UI must" >&227 echo " point at the container host running the API. Set API_BASE in the" >&228 echo " Vercel project settings, e.g. https://jobfetch.onrender.com" >&229 exit 130fi31 32# Strip any trailing slash so the page builds "<base>/api/scrape" cleanly.33API_BASE="${API_BASE%/}"34 35case "$API_BASE" in36 https://*) ;;37 http://localhost*|http://127.0.0.1*) ;;38 *)39 echo "build-vercel: API_BASE must be https:// (got '$API_BASE')." >&240 echo " A Vercel page is served over HTTPS, so a plain-http API origin is" >&241 echo " blocked as mixed content and every request fails silently." >&242 exit 143 ;;44esac45 46mkdir -p "$OUT"47# `#` as the delimiter: the value contains slashes.48sed "s#<meta name=\"jobfetch-api-base\" content=\"\" />#<meta name=\"jobfetch-api-base\" content=\"$API_BASE\" />#" \49 "$SRC" > "$OUT/index.html"50 51if ! grep -q "content=\"$API_BASE\"" "$OUT/index.html"; then52 echo "build-vercel: failed to stamp API_BASE — the meta tag in $SRC changed." >&253 exit 154fi55 56echo "build-vercel: wrote $OUT/index.html pointing at $API_BASE"57 