Skip to content

Commit af0eca4

Browse files
Copilotitsfuad
andcommitted
feat: add one-command Linux run script with self-contained Redis and allow-all-origins
Co-authored-by: itsfuad <49100463+itsfuad@users.noreply.github.com>
1 parent 69ddb4e commit af0eca4

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

docker-compose.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
services:
2+
redis:
3+
image: redis:alpine
4+
restart: unless-stopped
5+
healthcheck:
6+
test: ["CMD", "redis-cli", "ping"]
7+
interval: 5s
8+
timeout: 3s
9+
retries: 5
10+
11+
server:
12+
build: .
13+
ports:
14+
- "5000:5000"
15+
environment:
16+
host: redis
17+
port: 6379
18+
password: ""
19+
devMode: "true"
20+
adminPasskey: ""
21+
clienturl: ""
22+
depends_on:
23+
redis:
24+
condition: service_healthy
25+
restart: unless-stopped

run.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
echo "Starting Poketab API with self-contained Redis..."
5+
6+
# Prefer 'docker compose' (v2 plugin) but fall back to 'docker-compose' (v1 standalone)
7+
if docker compose version &>/dev/null; then
8+
COMPOSE_CMD="docker compose"
9+
elif command -v docker-compose &>/dev/null; then
10+
COMPOSE_CMD="docker-compose"
11+
else
12+
echo "Error: neither 'docker compose' nor 'docker-compose' is available." >&2
13+
exit 1
14+
fi
15+
16+
$COMPOSE_CMD up --build

server/libs/websockets.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import { redis, Key, User, _R_getAllUsersData, _R_exitUserFromSocket, _R_deleteC
88
import { validatename, validateKey } from './utils.ts';
99

1010
//get client url from .env file which will be set to CORS
11-
const { clienturl, host, port, password } = Deno.env.toObject();
11+
const { clienturl, host, port, password, devMode } = Deno.env.toObject();
12+
13+
const allowAllOrigins = devMode === 'true';
1214

1315
const [pubClient, subClient] = await Promise.all([
1416
createRedisClient({
@@ -28,9 +30,9 @@ pubClient.hset('server', 'status', 'online');
2830
//initialize socket.io server
2931
export const io = new Server({
3032
cors: {
31-
origin: [clienturl],
33+
origin: allowAllOrigins ? '*' : [clienturl],
3234
methods: ["GET", "POST"],
33-
credentials: true
35+
credentials: !allowAllOrigins,
3436
},
3537
adapter: createRedisAdapter(pubClient, subClient),
3638
});

0 commit comments

Comments
 (0)