Swift server with proxy and web sockets

Greetings!

I'm trying to build a small infrastructure piece around a web app that I have. The web app is basically a bunch of static files that talk to some backend. I don't have direct access to this backend except for RESTful API.

My current setup is Node.js based. It is an HTTP server that serves static files under /public route and proxies everything else to a particular backend. The frontend doesn't need to know what the backend is, from the code perspective it talks to its own server. Additionally, websocket connection is proxied using the same approach.

What tools can I use to implement this in Swift? Any existing open source examples that cover this? Any de-facto solutions in the community that I can start working with?

Thanks

SwiftNIO provides all the tools you'd need: We've got modules for HTTP/1, HTTP/2, WebSocket, and much more. SwiftNIO will definitely be able to handle the job but it's fairly low-level so if you're not familiar with it (or Netty) already there might be a bit of a learning curve but we've happy to help :slight_smile:.

There are plenty of examples of web servers and WebSocket libraries written using SwiftNIO, we've got a CONNECT proxy example too in the swift-nio-examples repository.

If you have any questions, please feel free to ask questions in the Related Projects > SwiftNIO category.

Any plans for SwiftNIO to add http/3 QUIC support?

It's definitely something we're interested in. In an ideal world we'd build a pure-Swift implementation, and in the long term we definitely want to do that. However, the amount of work involved in that is enormous, and fundamentally we haven't identified it as a critical need for Swift on Server at this moment. We think our efforts would be better focused elsewhere for now, particularly on making further investments in the wider Swift on Server community.

With that said, we'll continue to be responsive to user needs on this front.

2 Likes