this repo has no description
1#!/bin/bash
2# Test cross-origin demo end-to-end.
3# Starts page server (8080) and CORS universe server (9090),
4# then runs Playwright to verify cross-origin loading works.
5set -euo pipefail
6
7SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
8MONO=$(cd "$SCRIPT_DIR/.." && pwd)
9DOC_HTML="$MONO/_build/default/_doc/_html/odoc-interactive-extension"
10CROSSORIGIN_DIR="$MONO/_build/default/_doc/_html/_crossorigin_universes"
11
12cleanup() {
13 [[ -n "${PAGE_PID:-}" ]] && kill "$PAGE_PID" 2>/dev/null || true
14 [[ -n "${CORS_PID:-}" ]] && kill "$CORS_PID" 2>/dev/null || true
15 wait 2>/dev/null || true
16}
17trap cleanup EXIT
18
19echo "=== Building demos ==="
20bash "$SCRIPT_DIR/deploy.sh" --no-serve
21
22echo ""
23echo "=== Starting servers ==="
24
25# Page server on port 8080
26cd "$DOC_HTML/.."
27python3 -m http.server 8080 &>/dev/null &
28PAGE_PID=$!
29
30# CORS universe server on port 9090
31python3 "$SCRIPT_DIR/cors_server.py" 9090 "$CROSSORIGIN_DIR" &>/dev/null &
32CORS_PID=$!
33
34sleep 2
35echo " Page server: http://localhost:8080 (PID $PAGE_PID)"
36echo " CORS server: http://localhost:9090 (PID $CORS_PID)"
37
38# Verify both servers respond
39curl -sf http://localhost:8080/odoc-interactive-extension/demo4_crossorigin.html > /dev/null \
40 || { echo "FAIL: page server not responding"; exit 1; }
41curl -sf http://localhost:9090/universe/findlib_index.json > /dev/null \
42 || { echo "FAIL: CORS server not responding"; exit 1; }
43
44# Verify CORS headers
45CORS_HEADER=$(curl -sI http://localhost:9090/universe/findlib_index.json | grep -i 'access-control-allow-origin' || true)
46if [[ -z "$CORS_HEADER" ]]; then
47 echo "FAIL: CORS server missing Access-Control-Allow-Origin header"
48 exit 1
49fi
50echo " CORS header: $CORS_HEADER"
51
52echo ""
53echo "=== Running Playwright test ==="
54NODE_PATH="$MONO/x-ocaml/test/node_modules" node "$SCRIPT_DIR/test_crossorigin.js"