From 7b3524fcecb180b70632e80fa9f175097ef4d48c Mon Sep 17 00:00:00 2001 From: Mahak Date: Sat, 23 May 2026 00:20:46 -0400 Subject: [PATCH 1/4] Refactor: Add support for configurable backend proxy target in client via env var --- client/vite.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/vite.config.ts b/client/vite.config.ts index 34ccd044..6969957c 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -16,7 +16,7 @@ export default defineConfig({ allowedHosts: allowedHosts, proxy: { '/api': { - target: 'http://localhost:5000', + target: process.env.BACKEND_API_TARGET || 'http://localhost:5000', changeOrigin: true, }, }, From 049edc8d606c449754c2627398d1b1aa2b9cca83 Mon Sep 17 00:00:00 2001 From: Mahak Date: Sat, 23 May 2026 00:22:24 -0400 Subject: [PATCH 2/4] Feature: add Docker-based dev environment --- .gitignore | 2 -- Dockerfile.dev | 23 ++++++++++++++ docker-compose-dev.yaml | 70 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 Dockerfile.dev create mode 100644 docker-compose-dev.yaml diff --git a/.gitignore b/.gitignore index ff503dd0..1adbcf7b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,4 @@ dist kube.yml -docker-compose-dev.yaml - example-fragment.js \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 00000000..ece13a91 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,23 @@ +# Development image for ByteStash +FROM node:22-alpine AS base + + +FROM base AS client +# Install the dependencies from client +WORKDIR /client +COPY client/package.json ./ +RUN npm install +EXPOSE 3000 +CMD ["npm", "run", "start", "--", "--host"] + + +FROM base AS server +# Install the dependencies from server +WORKDIR /server +COPY server/package.json ./ +RUN apk add --no-cache --virtual .build-deps python3 make g++ gcc +RUN npm install +# Create directory for snippets +RUN mkdir -p /data/snippets +EXPOSE 5000 +CMD ["npx", "nodemon", "--watch", "src", "src/app.js"] \ No newline at end of file diff --git a/docker-compose-dev.yaml b/docker-compose-dev.yaml new file mode 100644 index 00000000..86f203fe --- /dev/null +++ b/docker-compose-dev.yaml @@ -0,0 +1,70 @@ +services: + client: + build: + context: . + target: client + dockerfile: Dockerfile.dev + ports: + - "3000:3000" + environment: + # Backend API taget: Points to the ExpressJS container running the REST APIs + - BACKEND_API_TARGET=http://server:5000 + volumes: + - "./client:/client" + - "/client/node_modules" + server: + build: + context: . + target: server + dockerfile: Dockerfile.dev + ports: + - "5000:5000" + environment: + # e.g. write /bytestash for a domain such as my.domain/bytestash, leave blank in every other case + - BASE_PATH= + # optionally include additional allowed hosts for reverse proxies + # e.g. localhost,my.domain.com,my.domain.net + - ALLOWED_HOSTS= + # Either provide JWT_SECRET directly or use JWT_SECRET_FILE for Docker secrets + #- JWT_SECRET_FILE=/run/secrets/jwt + - JWT_SECRET=your-secret + # how long the token lasts, examples: "2 days", "10h", "7d", "1m", "60s" + - TOKEN_EXPIRY=24h + # is this bytestash instance open to new accounts being created? + - ALLOW_NEW_ACCOUNTS=true + # Should debug mode be enabled? Essentially enables logging, in most cases leave this as false + - DEBUG=false + # Should we use accounts at all? When enabled, it will be like starting a fresh account so export your snippets, no login required + - DISABLE_ACCOUNTS=false + # Should internal accounts be disabled? + - DISABLE_INTERNAL_ACCOUNTS=false + # Allow password changes (false by default) + - ALLOW_PASSWORD_CHANGES=true + + # Optional: Enable OIDC for Single Sign On + - OIDC_ENABLED=true + # Optional: Display name for users signing in with SSO, will default to Single Sign-on + - OIDC_DISPLAY_NAME= + # Your OIDC issuer url, e.g. https://authentik.mydomain.com/application/o/bytestash/ for authentik + - OIDC_ISSUER_URL= + # Your OIDC client ID, you can find it in your app provider + - OIDC_CLIENT_ID= + # Your OIDC client secret, again, found in the app provider + - OIDC_CLIENT_SECRET= + # The OIDC scopes to request, e.g. "openid profile email groups" + - OIDC_SCOPES= + # Optional: Comma-separated list of usernames that should have admin privileges + # e.g. "admin,jordan" - these users will have access to the admin panel + - ADMIN_USERNAMES=admin + volumes: + - "./server:/server" + - "/server/node_modules" + - ./data:/data/snippets + +# Uncomment to use docker secrets +# secrets: +# - jwt + +#secrets: +# jwt: +# file: ./secrets/jwt.txt From 172b1658c613ee86559b83895010a86547ba4808 Mon Sep 17 00:00:00 2001 From: Mahak Date: Sat, 23 May 2026 00:22:58 -0400 Subject: [PATCH 3/4] Feature: add dev environment bootstrap script --- start-dev.sh | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100755 start-dev.sh diff --git a/start-dev.sh b/start-dev.sh new file mode 100755 index 00000000..5de6e020 --- /dev/null +++ b/start-dev.sh @@ -0,0 +1,162 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ────────────────────────────────────────────── +# ByteStash Dev Environment Setup & Launch +# ────────────────────────────────────────────── + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +info() { echo -e "${GREEN}[INFO]${NC} $1"; } +warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } +error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } + +# ────────────────────────────────────────────── +# 1. OS Detection +# ────────────────────────────────────────────── +detect_os() { + case "$(uname -s)" in + Linux*) OS="linux" ;; + Darwin*) OS="macos" ;; + CYGWIN*|MINGW*|MSYS*) + error "Windows is not supported. Please use WSL (Windows Subsystem for Linux)." ;; + *) + error "Unsupported operating system: $(uname -s)" ;; + esac + info "Detected OS: $OS" +} + +# ────────────────────────────────────────────── +# 2. Docker Check +# ────────────────────────────────────────────── +check_docker() { + if ! command -v docker &>/dev/null; then + error "Docker is not installed. Please install Docker first: https://docs.docker.com/get-docker/" + fi + + if ! docker info &>/dev/null; then + error "Docker daemon is not running. Please start Docker and try again." + fi + + info "Docker is installed and running." +} + +# ────────────────────────────────────────────── +# 3. NVM + Node Check +# ────────────────────────────────────────────── +check_nvm_and_node() { + export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" + + if [[ -s "$NVM_DIR/nvm.sh" ]]; then + source "$NVM_DIR/nvm.sh" + fi + + if ! command -v nvm &>/dev/null; then + error "nvm is not installed. Install it from: https://github.com/nvm-sh/nvm#installing-and-updating" + fi + + info "nvm is installed." + + if ! node --version &>/dev/null; then + warn "No active Node.js version found. Installing Node 22 via nvm..." + nvm install 22 + fi + + NODE_MAJOR=$(node --version | sed 's/v\([0-9]*\).*/\1/') + if [[ "$NODE_MAJOR" -ne 22 ]]; then + warn "Node.js $(node --version) detected. Switching to Node 22 to match the dev container..." + nvm install 22 + nvm use 22 + fi + + info "Node.js $(node --version) is active." +} + +# ────────────────────────────────────────────── +# 4. Build Dependencies Check (native modules) +# ────────────────────────────────────────────── +check_build_deps() { + local missing=() + + for cmd in python3 make gcc g++; do + if ! command -v "$cmd" &>/dev/null; then + missing+=("$cmd") + fi + done + + if [[ ${#missing[@]} -gt 0 ]]; then + warn "Missing build dependencies: ${missing[*]}" + echo "" + if [[ "$OS" == "macos" ]]; then + echo " Install Xcode CLI tools: xcode-select --install" + echo " Install Python 3: brew install python3" + elif [[ "$OS" == "linux" ]]; then + echo " Debian/Ubuntu: sudo apt install build-essential python3" + echo " Fedora/RHEL: sudo dnf install gcc gcc-c++ make python3" + echo " Arch: sudo pacman -S base-devel python" + fi + echo "" + error "Please install the missing dependencies and re-run this script." + fi + + info "Build dependencies are available." +} + +# ────────────────────────────────────────────── +# 5. Docker Compose Variant Detection +# ────────────────────────────────────────────── +detect_compose() { + if docker compose version &>/dev/null; then + COMPOSE="docker compose" + elif command -v docker-compose &>/dev/null; then + COMPOSE="docker-compose" + else + error "Neither 'docker compose' nor 'docker-compose' is available. Please install Docker Compose." + fi + + info "Using compose command: $COMPOSE" +} + +# ────────────────────────────────────────────── +# 6. Install Dependencies & Launch +# ────────────────────────────────────────────── +install_and_launch() { + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + cd "$SCRIPT_DIR" + + if [[ ! -f "docker-compose-dev.yaml" ]]; then + error "docker-compose-dev.yaml not found. Run this script from the ByteStash project root." + fi + + info "Installing client dependencies..." + npm install --prefix client + + info "Installing server dependencies..." + npm install --prefix server + + info "Starting dev containers..." + $COMPOSE -f docker-compose-dev.yaml up --build +} + +# ────────────────────────────────────────────── +# Main +# ────────────────────────────────────────────── +main() { + echo "" + echo "=========================================" + echo " ByteStash Dev Environment Setup" + echo "=========================================" + echo "" + + detect_os + check_docker + check_nvm_and_node + check_build_deps + detect_compose + install_and_launch +} + +main \ No newline at end of file From a6a4b9d9709146a1bc0d51c5908b671f3a5fdf22 Mon Sep 17 00:00:00 2001 From: Mahak Date: Sat, 23 May 2026 03:26:22 -0400 Subject: [PATCH 4/4] FIX: Update bootstrap script to clear anonymous volumes before starting dev containers --- start-dev.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/start-dev.sh b/start-dev.sh index 5de6e020..e2f86bd9 100755 --- a/start-dev.sh +++ b/start-dev.sh @@ -137,6 +137,9 @@ install_and_launch() { info "Installing server dependencies..." npm install --prefix server + info "Cleaning old containers and volumes..." + $COMPOSE -f docker-compose-dev.yaml down -v + info "Starting dev containers..." $COMPOSE -f docker-compose-dev.yaml up --build }