Skip to content

Commit c8ba8d6

Browse files
updated devcontainer to expose socket api file, improve socket api
1 parent 1befdce commit c8ba8d6

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
2828
npm install -g npm@latest
2929

3030
# Set up non-root user and workspace
31+
32+
RUN mkdir -p /tmp/ssui && chmod 777 /tmp/ssui
3133
USER vscode
3234
WORKDIR /workspaces

.devcontainer/devcontainer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
},
99
"workspaceFolder": "/workspaces/project",
1010
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/project,type=bind,consistency=cached",
11+
"mounts": [
12+
"source=ssui-socket-volume,target=/tmp/ssui,type=volume"
13+
],
1114
"features": {
1215
"ghcr.io/devcontainers/features/go:1": {
1316
"version": "1.25.0"

src/api/socketapi/examples.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This guide explains how to interact with the socket-based `SSUI-API`, which expo
55
## Overview
66

77
The socket server reuses the HTTP routes defined in `routes.go` but serves them over:
8-
- **Linux**: A Unix socket at `/tmp/ssui.sock`.
8+
- **Linux**: A Unix socket at `/tmp/ssui/ssui.sock`.
99
- **Windows**: A named pipe at `\\.\pipe\ssui`.
1010

1111
This is similar to how Docker uses `/var/run/docker.sock` for local API access.
@@ -27,7 +27,7 @@ This is similar to how Docker uses `/var/run/docker.sock` for local API access.
2727
Use `curl` with the `--unix-socket` flag to send HTTP requests to the socket. Example for the `/api/v2/settings` endpoint:
2828

2929
```bash
30-
curl --unix-socket /tmp/ssui.sock http://localhost/api/v2/settings
30+
curl --unix-socket /tmp/ssui/ssui.sock http://localhost/api/v2/settings
3131
```
3232

3333
**Expected Output**: JSON response from the `settings.RetrieveSettings` handler, e.g.:
@@ -110,14 +110,14 @@ All routes from `routes.go` (e.g., `/api/v2/server/start`, `/api/v2/backups`) ar
110110

111111
- **Linux**:
112112
```bash
113-
curl --unix-socket /tmp/ssui.sock http://localhost/api/v2/backups
113+
curl --unix-socket /tmp/ssui/ssui.sock http://localhost/api/v2/backups
114114
```
115115
- **Windows**: Edit `$endpoint` in `test_namedpipe.ps1`, e.g., `$endpoint = "/api/v2/backups"`.
116116

117117
For POST requests (e.g., `/api/v2/server/start`), add a JSON payload:
118118
- **Linux**:
119119
```bash
120-
curl --unix-socket /tmp/ssui.sock -X POST -H "Content-Type: application/json" -d '{"action":"start"}' http://localhost/api/v2/server/start
120+
curl --unix-socket /tmp/ssui/ssui.sock -X POST -H "Content-Type: application/json" -d '{"action":"start"}' http://localhost/api/v2/server/start
121121
```
122122
- **Windows**: Update the PowerShell script’s `$request`:
123123
```powershell

src/api/socketapi/socket-lin.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import (
99
"net"
1010
"net/http"
1111
"os"
12+
"path/filepath"
1213
"sync"
1314

1415
"github.com/SteamServerUI/SteamServerUI/v7/src/api"
1516
"github.com/SteamServerUI/SteamServerUI/v7/src/logger"
1617
)
1718

18-
const socketPath = "/tmp/ssui.sock"
19+
const socketPath = "/tmp/ssui/ssui.sock"
1920

2021
func StartSocketServer(wg *sync.WaitGroup) {
2122
logger.Socket.Info("Starting Unix socket server...")
@@ -30,6 +31,12 @@ func StartSocketServer(wg *sync.WaitGroup) {
3031
api.SetupSocketAPIRoutes(APIMux)
3132
mux.Handle("/", APIMux)
3233

34+
// Create parent directory for the socket
35+
parentDir := filepath.Dir(socketPath)
36+
if err := os.MkdirAll(parentDir, 0755); err != nil {
37+
logger.Socket.Error("Error creating parent directory: " + err.Error())
38+
return
39+
}
3340
// Create Unix socket listener
3441
listener, err := net.Listen("unix", socketPath)
3542
if err != nil {

0 commit comments

Comments
 (0)