Skip to content

Commit 1f7e362

Browse files
committed
status api
1 parent 7ddf6a2 commit 1f7e362

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

packages/server/src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import SocketHandler from "./lib/socket";
88
import RequestMiddleware from "./middlewares/request";
99
import { RequestChannel } from "./lib/tunnel";
1010
import { debug } from "./utils/debug";
11+
import { extractIdFromDomain, isValidSocketId } from './utils/domain';
1112

1213
// Timing-safe token comparison to prevent timing attacks
1314
function timingSafeEqual(a: string, b: string): boolean {
@@ -31,6 +32,18 @@ app.use(express.urlencoded({ extended: true }));
3132
app.use(express.json());
3233
app.use(cors());
3334

35+
app.get('/status', (req, res, next) => {
36+
const id = extractIdFromDomain(req.hostname);
37+
if (id && isValidSocketId(id)) {
38+
return next(); // tunnel subdomain — let proxy handle it
39+
}
40+
res.json({
41+
status: 'ok',
42+
uptime: process.uptime(),
43+
version: socketHandler.getVersion(),
44+
});
45+
});
46+
3447
app.use("/", RequestMiddleware, (req, res) => {
3548
const socketId: any = req.id;
3649

packages/server/src/lib/socket.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ class SocketHandler {
151151
});
152152
}
153153

154+
public getVersion(): string {
155+
return this.version;
156+
}
157+
154158
public getTunnelByStableId(stableTunnelId: string): TunnelMapping | undefined {
155159
const mapping = this.tunnelMappings.get(stableTunnelId);
156160
if (mapping) {

0 commit comments

Comments
 (0)