Update
This commit is contained in:
1 parent
911dcace72
commit
9c68c414d8
53 files changed
+2919
-469
No files matched your search
@@ -0,0 +1,29 @@
|
||||
import express from 'express'
|
||||
import './database'
|
||||
import { rpcModules } from './rpcModules'
|
||||
|
||||
const app = express()
|
||||
app.use(express.json({ limit: '50mb' })) // Backup-Import kann alle Tabellen als ein JSON-Body enthalten
|
||||
|
||||
app.post('/api/rpc', (req, res) => {
|
||||
const { module, fn, args } = req.body as { module?: string; fn?: string; args?: unknown[] }
|
||||
|
||||
const mod = module ? rpcModules[module] : undefined
|
||||
const handler = fn ? mod?.[fn] : undefined
|
||||
if (!mod || typeof handler !== 'function') {
|
||||
res.json({ ok: false, error: `Unbekannte RPC-Zielfunktion: ${module}.${fn}` })
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const result = handler(...(args ?? []))
|
||||
res.json({ ok: true, result: result ?? null })
|
||||
} catch (err) {
|
||||
res.json({ ok: false, error: err instanceof Error ? err.message : 'Unbekannter Server-Fehler' })
|
||||
}
|
||||
})
|
||||
|
||||
const port = process.env.API_PORT ? Number(process.env.API_PORT) : 4000
|
||||
app.listen(port, () => {
|
||||
console.log(`[server] RPC-API läuft auf http://localhost:${port}/api/rpc`)
|
||||
})
|
||||
Reference in new issue
Block a user