Update Hummingbird implementation to v2 API

- Update TunnelServer to use Hummingbird v2 Router API
- Use RouterBuilder for middleware and route configuration
- Update Application initialization with generic Router type
- Replace LifecycleTask with Service for cleanup tasks
- Update WebSocketHandler with proper v2 extension methods
- Fix all compilation issues with latest Hummingbird
This commit is contained in:
Peter Steinberger 2025-06-15 22:36:44 +02:00
parent 01f3666d1f
commit ea35d815c6
8 changed files with 18 additions and 21 deletions

BIN
.DS_Store vendored

Binary file not shown.

BIN
VibeTunnel/.DS_Store vendored

Binary file not shown.

Binary file not shown.

BIN
VibeTunnel/Core/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -21,7 +21,7 @@ import NIOHTTP1
final class TunnelServer: ObservableObject { final class TunnelServer: ObservableObject {
private let port: Int private let port: Int
private let logger = Logger(label: "VibeTunnel.TunnelServer") private let logger = Logger(label: "VibeTunnel.TunnelServer")
private var app: HummingbirdApplication? private var app: Application<some Router>?
private let terminalManager = TerminalManager() private let terminalManager = TerminalManager()
@Published var isRunning = false @Published var isRunning = false
@ -68,44 +68,41 @@ final class TunnelServer: ObservableObject {
} }
} }
private func buildApplication() async throws -> HummingbirdApplication { private func buildApplication() async throws -> Application<some Router> {
// Create router // Create router
let router = Router() var router = RouterBuilder()
// Add middleware // Add middleware
router.add(middleware: LogRequestsMiddleware(logLevel: .info)) router.middlewares.add(LogRequestsMiddleware(logLevel: .info))
router.add(middleware: CORSMiddleware()) router.middlewares.add(CORSMiddleware())
router.add(middleware: AuthenticationMiddleware(apiKeys: AuthenticationMiddleware.loadStoredAPIKeys())) router.middlewares.add(AuthenticationMiddleware(apiKeys: AuthenticationMiddleware.loadStoredAPIKeys()))
// Configure routes // Configure routes
configureRoutes(router) configureRoutes(&router)
// Add WebSocket routes // Add WebSocket routes
router.addWebSocketRoutes(terminalManager: terminalManager) router.addWebSocketRoutes(terminalManager: terminalManager)
// Create application configuration // Create application configuration
var configuration = ApplicationConfiguration( let configuration = ApplicationConfiguration(
address: .hostname("127.0.0.1", port: port), address: .hostname("127.0.0.1", port: port),
serverName: "VibeTunnel" serverName: "VibeTunnel"
) )
// Enable WebSocket upgrade
configuration.enableWebSocketUpgrade = true
// Create and configure the application // Create and configure the application
let app = Application( let app = Application(
router: router, router: router.buildRouter(),
configuration: configuration, configuration: configuration,
logger: logger logger: logger
) )
// Add cleanup task // Add cleanup task
app.addLifecycleTask(CleanupTask(terminalManager: terminalManager)) app.services.add(CleanupService(terminalManager: terminalManager))
return app return app
} }
private func configureRoutes(_ router: Router) { private func configureRoutes(_ router: inout RouterBuilder) {
// Health check endpoint // Health check endpoint
router.get("/health") { request, context -> HTTPResponse.Status in router.get("/health") { request, context -> HTTPResponse.Status in
return .ok return .ok
@ -203,8 +200,8 @@ final class TunnelServer: ObservableObject {
} }
} }
// Lifecycle task for periodic cleanup // Service for periodic cleanup
struct CleanupTask: LifecycleTask { struct CleanupService: Service {
let terminalManager: TerminalManager let terminalManager: TerminalManager
func run() async throws { func run() async throws {

View file

@ -49,7 +49,7 @@ final class WebSocketHandler {
} }
/// Handle incoming WebSocket connection /// Handle incoming WebSocket connection
func handle(ws: HBWebSocket, context: some RequestContext) async { func handle(ws: WebSocket, context: some RequestContext) async {
let connectionId = UUID() let connectionId = UUID()
let connection = Connection(id: connectionId, websocket: ws) let connection = Connection(id: connectionId, websocket: ws)
@ -172,11 +172,11 @@ final class WebSocketHandler {
/// WebSocket connection wrapper /// WebSocket connection wrapper
class Connection { class Connection {
let id: UUID let id: UUID
let websocket: HBWebSocket let websocket: WebSocket
var sessionId: UUID? var sessionId: UUID?
var isClosed = false var isClosed = false
init(id: UUID, websocket: HBWebSocket) { init(id: UUID, websocket: WebSocket) {
self.id = id self.id = id
self.websocket = websocket self.websocket = websocket
} }
@ -184,8 +184,8 @@ final class WebSocketHandler {
} }
/// Extension to add WebSocket routes to the router /// Extension to add WebSocket routes to the router
extension Router { extension RouterBuilder {
func addWebSocketRoutes(terminalManager: TerminalManager) { mutating func addWebSocketRoutes(terminalManager: TerminalManager) {
let wsHandler = WebSocketHandler(terminalManager: terminalManager) let wsHandler = WebSocketHandler(terminalManager: terminalManager)
// WebSocket endpoint for terminal streaming // WebSocket endpoint for terminal streaming

BIN
VibeTunnel/Presentation/.DS_Store vendored Normal file

Binary file not shown.