Compare commits
No commits in common. "1f0c7bd0996164d9fbba1333a115be0444d872ba" and "1e4d66cbe4a6fd0dc4bac3b9f6005111512ee1a6" have entirely different histories.
1f0c7bd099
...
1e4d66cbe4
|
|
@ -16,4 +16,3 @@ export {
|
|||
unshareApp,
|
||||
} from './manage'
|
||||
export { metricsApp } from './metrics'
|
||||
export { perfToggle } from './perf'
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
import color from 'ansis'
|
||||
import { get, post } from '../http'
|
||||
|
||||
export async function perfToggle(onOff?: string) {
|
||||
if (onOff && !['on', 'off', 'status'].includes(onOff)) {
|
||||
console.error('Usage: toes perf [on|off|status]')
|
||||
process.exit(1)
|
||||
}
|
||||
const body = onOff && onOff !== 'status' ? { on: onOff === 'on' } : {}
|
||||
const res = onOff === 'status'
|
||||
? await get<{ perfTiming: boolean }>('/api/system/perf')
|
||||
: await post<{ perfTiming: boolean }>('/api/system/perf', body)
|
||||
if (res) {
|
||||
const label = res.perfTiming ? color.green('on') : color.red('off')
|
||||
console.log(`Perf timing ${onOff === 'status' ? 'is ' : ''}${label}`)
|
||||
}
|
||||
}
|
||||
|
|
@ -16,15 +16,14 @@ import {
|
|||
infoApp,
|
||||
listApps,
|
||||
logApp,
|
||||
metricsApp,
|
||||
newApp,
|
||||
openApp,
|
||||
perfToggle,
|
||||
renameApp,
|
||||
restartApp,
|
||||
rmApp,
|
||||
shareApp,
|
||||
startApp,
|
||||
metricsApp,
|
||||
stopApp,
|
||||
unshareApp,
|
||||
} from './commands'
|
||||
|
|
@ -233,13 +232,6 @@ env
|
|||
.option('-g, --global', 'remove a global variable')
|
||||
.action(envRm)
|
||||
|
||||
program
|
||||
.command('perf')
|
||||
.helpGroup('Config:')
|
||||
.description('Toggle request timing for proxied app requests')
|
||||
.argument('[on|off|status]', 'enable, disable, or check status (toggles if omitted)')
|
||||
.action(perfToggle)
|
||||
|
||||
// Shell
|
||||
|
||||
program
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { allApps, APPS_DIR, onChange } from '$apps'
|
||||
import { perf } from '../proxy'
|
||||
import { onHostLog } from '../tui'
|
||||
import { Hype } from '@because/hype'
|
||||
import { cpus, freemem, platform, totalmem } from 'os'
|
||||
|
|
@ -284,16 +283,6 @@ onChange(collectLogs)
|
|||
// Subscribe to host-level log messages
|
||||
onHostLog(pushHostLog)
|
||||
|
||||
// Perf timing toggle
|
||||
router.get('/perf', c => c.json({ perfTiming: perf.timing }))
|
||||
router.post('/perf', async c => {
|
||||
const body = await c.req.json<{ on?: boolean }>().catch(() => ({}))
|
||||
const on = body.on ?? !perf.timing
|
||||
perf.timing = on
|
||||
console.log(`[perf] timing ${on ? 'enabled' : 'disabled'}`)
|
||||
return c.json({ perfTiming: on })
|
||||
})
|
||||
|
||||
// Restart server (systemd brings it back)
|
||||
router.post('/restart', c => {
|
||||
setTimeout(() => process.exit(0), 100)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import type { Server, ServerWebSocket } from 'bun'
|
||||
import { getAppBySubdomain } from '$apps'
|
||||
|
||||
export const perf = { timing: false }
|
||||
|
||||
export type { WsData }
|
||||
|
||||
const pendingMessages = new Map<ServerWebSocket<WsData>, (string | ArrayBuffer | Uint8Array)[]>()
|
||||
|
|
@ -55,19 +53,12 @@ export async function proxySubdomain(subdomain: string, req: Request): Promise<R
|
|||
headers.delete('transfer-encoding')
|
||||
|
||||
try {
|
||||
const shouldTime = perf.timing
|
||||
const start = shouldTime ? performance.now() : 0
|
||||
const res = await fetch(target, {
|
||||
return await fetch(target, {
|
||||
method: req.method,
|
||||
headers,
|
||||
body,
|
||||
redirect: 'manual',
|
||||
})
|
||||
if (shouldTime) {
|
||||
const ms = (performance.now() - start).toFixed(1)
|
||||
console.log(`[perf] ${req.method} ${subdomain}${url.pathname} → ${res.status} in ${ms}ms`)
|
||||
}
|
||||
return res
|
||||
} catch (e) {
|
||||
console.error(`Proxy error for ${subdomain}:`, e)
|
||||
return new Response(`App "${subdomain}" is not responding`, { status: 502 })
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user