Skip to content

Commit 881faf9

Browse files
committed
feat(server): serve prebuilt client via module API and inject runtime config
- Add app/client-path.js to resolve client public path via webssh2_client.getPublicPath() with fallback - Mount static assets under /ssh/assets using resolved client path (app/app.js) - Inject runtime webssh2Config and rewrite asset URLs in modifyHtml via connectionHandler - Update package metadata/lockfile for new dependency wiring Enables serving the Vite-built client from webssh2_client/client/public without rebundling, fixing browser-side “require is not defined” issues.
1 parent 74fa839 commit 881faf9

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
lines changed

app/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// app/app.js
33

44
import express from 'express'
5-
import webssh2Client from 'webssh2_client'
65
import config, { getConfig } from './config.js'
76
import SSHConnection from './ssh.js'
87
import socketHandler from './socket.js'
@@ -13,6 +12,7 @@ import { configureSocketIO } from './io.js'
1312
import { handleError, ConfigError } from './errors.js'
1413
import { createNamespacedDebug } from './logger.js'
1514
import { MESSAGES } from './constants.js'
15+
import { getClientPublicPath } from './client-path.js'
1616

1717
const debug = createNamespacedDebug('app')
1818

@@ -26,7 +26,7 @@ function createAppAsync(appConfig) {
2626

2727
try {
2828
// Resolve the correct path to the webssh2_client module
29-
const clientPath = webssh2Client.getPublicPath()
29+
const clientPath = getClientPublicPath()
3030

3131
// Apply middleware
3232
const { sessionMiddleware } = applyMiddleware(app, appConfig)
@@ -57,7 +57,7 @@ function createApp() {
5757

5858
try {
5959
// Resolve the correct path to the webssh2_client module
60-
const clientPath = webssh2Client.getPublicPath()
60+
const clientPath = getClientPublicPath()
6161

6262
// Apply middleware
6363
const { sessionMiddleware } = applyMiddleware(app, config)

app/client-path.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// server
2+
// app/client-path.js
3+
4+
import webssh2Client from 'webssh2_client'
5+
import { DEFAULTS } from './constants.js'
6+
import { createNamespacedDebug } from './logger.js'
7+
8+
const debug = createNamespacedDebug('client-path')
9+
10+
/**
11+
* Resolve the public path for the webssh2_client assets.
12+
* Prefers module API, falls back to DEFAULTS.WEBSSH2_CLIENT_PATH.
13+
* @returns {string} absolute path to client public assets
14+
*/
15+
export function getClientPublicPath() {
16+
try {
17+
const p = webssh2Client.getPublicPath()
18+
return p
19+
} catch (err) {
20+
debug('Falling back to DEFAULTS.WEBSSH2_CLIENT_PATH:', err?.message)
21+
return DEFAULTS.WEBSSH2_CLIENT_PATH
22+
}
23+
}

app/connectionHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
import { promises as fs } from 'fs'
55
import path from 'path'
6-
import webssh2Client from 'webssh2_client'
76
import { createNamespacedDebug } from './logger.js'
87
import { HTTP, MESSAGES, DEFAULTS } from './constants.js'
98
import { modifyHtml } from './utils.js'
9+
import { getClientPublicPath } from './client-path.js'
1010
const debug = createNamespacedDebug('connectionHandler')
1111

1212
/**
@@ -33,7 +33,7 @@ async function handleFileRead(filePath, config, res) {
3333
async function handleConnection(req, res) {
3434
debug('Handling connection req.path:', req.path)
3535

36-
const clientPath = webssh2Client.getPublicPath()
36+
const clientPath = getClientPublicPath()
3737

3838
const tempConfig = {
3939
socket: {

package-lock.json

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"debug": "^4.4.1",
3939
"express": "^5.1.0",
4040
"express-session": "^1.18.2",
41-
"jsmasker": "^1.7.0",
41+
"jsmasker": "^2.0.0",
4242
"socket.io": "^4.8.1",
4343
"ssh2": "1.17",
4444
"validator": "^13.15.15",

0 commit comments

Comments
 (0)