The server for Open Course World
at tangled-test 46 lines 820 B view raw
1#!/usr/bin/env bash 2 3. ./scripts/util.sh 4 5[[ -s "tmp/dev-user/vars.sh" ]] || { 6 if [[ -n "$IS_DOCKER" ]]; then 7 fail "can't find a running server on this image. use \`docker compose up app\` and then \`docker compose exec app $0\`" 8 else 9 fail "server is not running with dev user enabled" 10 fi 11} 12 13set -a 14. ./tmp/dev-user/vars.sh 15set +a 16 17check-exe curl "curl not found" 18 19get() { 20 local path="$1"; shift 21 22 execd curl -k \ 23 -H "Accept: application/json" \ 24 -H "Authorization: Bearer $OCW_TOKEN" \ 25 https://"$OCW_ADDRESS"/api/"$path" 26} 27 28websocket() { 29 wscat -w 6000 -x "$OCW_TOKEN" -n -c wss://"$OCW_ADDRESS"/api/live 30} 31 32usage() { 33 cat <<DOC >&2 34usage: 35 $0 get some/path 36 $0 websocket 37DOC 38} 39 40cmd="$1"; shift 41 42case cmd in 43 get) get "$@" ;; 44 websocket|ws) websocket "$@" ;; 45 *) get "$cmd" "$@" 46esac