Post

Replies

Boosts

Views

Activity

How can I set up a web application server using swifter?
I have an angular project that I want to deploy using swifter in swiftUI. I have tried the below code. import Foundation import Swifter class WebServer { let server = HttpServer() let path: String init(path: String) { self.path = path } func startServer() { if let webAppPath = Bundle.main.path(forResource: "index", ofType: "html", inDirectory: "fileDir") { // Serve the Flutter web build files server["/"] = shareFilesFromDirectory(webAppPath) server["/hello"] = { .ok(.htmlBody("You asked for \($0)")) } do { try server.start(8081) print("Web server started on port 8081") } catch { print("Failed to start the web server: \(error)") } } else { print("Web app path not found.") } } func stopServer() { server.stop() print("Web server stopped") } } When trying this, web server is starting successfully, but when running baseUrl on localhost 8081, it gives 404. On "/hello", it does work correctly. I am sure all the files are there in the directory given in fileDir. Also I have tried running it using npm http-server, and it running correctly with it. Can someone point out the issue here? Or point me to any github repo which is achieving same with maybe a different package
0
0
623
Jul ’23