From e4f2f16290ad180b1a8f22e56d9b44c4de6860d8 Mon Sep 17 00:00:00 2001 From: Mudassir Shabbir Date: Thu, 8 Aug 2024 20:14:45 +0500 Subject: [PATCH] fix: set GHCS domain name and port visibility --- .devcontainer/devcontainer.json | 35 +++++++++++++++++++++++++++++++++ make_ports_public.sh | 19 ++++++++++++++++++ ui/package.json | 2 +- ui/src/App.tsx | 8 ++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/devcontainer.json create mode 100755 make_ports_public.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..77c2a83 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,35 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node +{ + "name": "Node.js", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/javascript-node:1-18-bookworm", + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [5173, 1317, 26657, 26656], + "portsAttributes": { + "5173": { + "label": "UI", + "onAutoForward": "openBrowser" + }, + "1317": { + "label": "API", + "onAutoForward": "silent" + }, + "26657": { + "label": "RPC", + "onAutoForward": "silent" + }, + "26656": { + "label": "P2P", + "onAutoForward": "silent" + } + }, + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "bash /workspaces/dapp-offer-up/make_ports_public.sh 26657 5173 1317", + "postStartCommand": "yarn install", + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers/features/github-cli:1": {} + } +} diff --git a/make_ports_public.sh b/make_ports_public.sh new file mode 100755 index 0000000..f8f49ca --- /dev/null +++ b/make_ports_public.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -x + +# Function to change port visibility to public +change_port_visibility() { + local port=$1 + gh codespace ports visibility $port:public -c $CODESPACE_NAME +} + +# Check if at least one port is provided +if [ $# -eq 0 ]; then + echo "Usage: $0 [port2 ... portN]" + exit 1 +fi + +# Loop through each provided port and change its visibility to public +for port in "$@"; do + change_port_visibility $port +done diff --git a/ui/package.json b/ui/package.json index 664db26..608cbaa 100644 --- a/ui/package.json +++ b/ui/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", + "dev": "export VITE_HOSTNAME=$CODESPACE_NAME && export VITE_GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN=$GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN && vite", "build": "tsc && vite build", "test": "vitest spec", "test:e2e": "SKIP_EXTENSION_SETUP=true EXTENSION=keplr synpress run --configFile=test/e2e/synpress.config.cjs", diff --git a/ui/src/App.tsx b/ui/src/App.tsx index d62c47a..5e8bef2 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -25,6 +25,14 @@ const ENDPOINTS = { API: 'http://localhost:1317', }; +const codeSpaceHostName = import.meta.env.VITE_HOSTNAME; +const codeSpaceDomain = import.meta.env.VITE_GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN; + +if (codeSpaceHostName) { + ENDPOINTS.API = `https://${codeSpaceHostName}-1317.${codeSpaceDomain}`; + ENDPOINTS.RPC = `https://${codeSpaceHostName}-26657.${codeSpaceDomain}`; +} + const watcher = makeAgoricChainStorageWatcher(ENDPOINTS.API, 'agoriclocal'); interface AppState {