Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
redis:
image: redis:alpine
command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}"]
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
interval: 5s
timeout: 3s
retries: 5

server:
build: .
ports:
- "5000:5000"
environment:
host: redis
port: 6379
password: "${REDIS_PASSWORD}"
devMode: "true"
adminPasskey: ""
clienturl: ""
depends_on:
redis:
condition: service_healthy
restart: unless-stopped
27 changes: 27 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail

echo "Starting Poketab API with self-contained Redis..."

if docker compose version &>/dev/null; then
COMPOSE_CMD="docker compose"
elif command -v docker-compose &>/dev/null; then
COMPOSE_CMD="docker-compose"
else
echo "Error: neither 'docker compose' nor 'docker-compose' is available." >&2
exit 1
fi

if [ -z "${REDIS_PASSWORD:-}" ]; then
read -rsp "Enter Redis password: " REDIS_PASSWORD
echo
fi

if [ -z "$REDIS_PASSWORD" ]; then
echo "Error: REDIS_PASSWORD cannot be empty." >&2
exit 1
fi

export REDIS_PASSWORD

$COMPOSE_CMD up --build
8 changes: 5 additions & 3 deletions server/libs/websockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { redis, Key, User, _R_getAllUsersData, _R_exitUserFromSocket, _R_deleteC
import { validatename, validateKey } from './utils.ts';

//get client url from .env file which will be set to CORS
const { clienturl, host, port, password } = Deno.env.toObject();
const { clienturl, host, port, password, devMode } = Deno.env.toObject();

const allowAllOrigins = devMode === 'true';

const [pubClient, subClient] = await Promise.all([
createRedisClient({
Expand All @@ -28,9 +30,9 @@ pubClient.hset('server', 'status', 'online');
//initialize socket.io server
export const io = new Server({
cors: {
origin: [clienturl],
origin: allowAllOrigins ? '*' : [clienturl],
methods: ["GET", "POST"],
credentials: true
credentials: !allowAllOrigins,
},
adapter: createRedisAdapter(pubClient, subClient),
});
Expand Down
Loading