feat: disable static file serving in relay mode

When relay mode is enabled, skip serving frontend assets through the relay tunnel to reduce bandwidth pressure. Instead, show a helpful page on root directing users to the official frontend at app.hapi.run.

Changes:
- server/src/web/server.ts: Add relayMode and officialWebUrl options, skip static serving in relay mode, show helpful page on root
- server/src/index.ts: Pass relayMode and officialWebUrl to startWebServer
This commit is contained in:
weishu
2026-01-14 10:49:37 +08:00
parent c3c89a2773
commit ce88171d8e
2 changed files with 35 additions and 2 deletions
+3 -1
View File
@@ -208,7 +208,9 @@ async function main() {
store,
vapidPublicKey: vapidKeys.publicKey,
socketEngine: socketServer.engine,
corsOrigins
corsOrigins,
relayMode: relayFlag.enabled,
officialWebUrl
})
// Start the bot if configured
+32 -1
View File
@@ -61,6 +61,8 @@ function createWebApp(options: {
vapidPublicKey: string
corsOrigins?: string[]
embeddedAssetMap: Map<string, EmbeddedWebAsset> | null
relayMode?: boolean
officialWebUrl?: string
}): Hono<WebAppEnv> {
const app = new Hono<WebAppEnv>()
@@ -93,6 +95,31 @@ function createWebApp(options: {
app.route('/api', createGitRoutes(options.getSyncEngine))
app.route('/api', createPushRoutes(options.store, options.vapidPublicKey))
// Skip static serving in relay mode, show helpful message on root
if (options.relayMode) {
const officialUrl = options.officialWebUrl || 'https://app.hapi.run'
app.get('/', (c) => {
return c.html(`<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><title>HAPI Server</title></head>
<body style="font-family: system-ui; padding: 2rem; max-width: 600px;">
<h1>HAPI Server</h1>
<p>This server is running in relay mode. Please use the official web app:</p>
<p><a href="${officialUrl}">${officialUrl}</a></p>
<details>
<summary>Why am I seeing this?</summary>
<p style="margin-top: 0.5rem; color: #666;">
When relay mode is enabled, all traffic flows through our relay infrastructure with end-to-end encryption.
To reduce bandwidth and improve performance, the frontend is served separately
from GitHub Pages instead of through the relay tunnel.
</p>
</details>
</body>
</html>`)
})
return app
}
if (options.embeddedAssetMap) {
const embeddedAssetMap = options.embeddedAssetMap
const indexHtmlAsset = embeddedAssetMap.get('/index.html')
@@ -180,6 +207,8 @@ export async function startWebServer(options: {
vapidPublicKey: string
socketEngine: SocketEngine
corsOrigins?: string[]
relayMode?: boolean
officialWebUrl?: string
}): Promise<BunServer<WebSocketData>> {
const isCompiled = isBunCompiled()
const embeddedAssetMap = isCompiled ? await loadEmbeddedAssetMap() : null
@@ -191,7 +220,9 @@ export async function startWebServer(options: {
store: options.store,
vapidPublicKey: options.vapidPublicKey,
corsOrigins: options.corsOrigins,
embeddedAssetMap
embeddedAssetMap,
relayMode: options.relayMode,
officialWebUrl: options.officialWebUrl
})
const socketHandler = options.socketEngine.handler()