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

View file

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

BIN
VibeTunnel/Presentation/.DS_Store vendored Normal file

Binary file not shown.