@cappitolian/http-local-server-swifter 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,12 +59,19 @@ public protocol HttpLocalServerSwifterDelegate: AnyObject {
59
59
 
60
60
  private func setupHandlers() {
61
61
  guard let server = webServer else { return }
62
+
63
+ // This closure handles EVERY request regardless of the path
62
64
  let handler: ((HttpRequest) -> HttpResponse) = { [weak self] request in
63
- if request.method == "OPTIONS" { return self?.corsResponse() ?? .noContent }
64
- return self?.processRequest(request) ?? .internalServerError
65
+ if request.method == "OPTIONS" {
66
+ return self?.corsResponse() ?? .raw(204, "No Content", nil, nil)
67
+ }
68
+ return self?.processRequest(request) ?? .raw(500, "Internal Server Error", nil, nil)
69
+ }
70
+
71
+ // Swifter needs a wildcard to catch everything including subpaths like /orders/123
72
+ server.middleware.append { request in
73
+ return handler(request)
65
74
  }
66
- server["/"] = handler
67
- server["/:path"] = handler
68
75
  }
69
76
 
70
77
  private func processRequest(_ request: HttpRequest) -> HttpResponse {
@@ -159,4 +166,4 @@ public protocol HttpLocalServerSwifterDelegate: AnyObject {
159
166
  }
160
167
  return address
161
168
  }
162
- }
169
+ }
@@ -23,18 +23,22 @@ public class HttpLocalServerSwifterPlugin: CAPPlugin, CAPBridgedPlugin, HttpLoca
23
23
  localServer = nil
24
24
  }
25
25
 
26
- @objc func sendResponse(_ call: CAPPluginCall) {
27
- guard let requestId = call.getString("requestId") else {
28
- call.reject("Missing requestId")
29
- return
30
- }
31
- // Send the entire JS dictionary to handleJsResponse
32
- // This includes 'body', 'status', and 'headers'
33
- HttpLocalServerSwifter.handleJsResponse(requestId: requestId, responseData: call.dictionaryRepresentation)
34
- call.resolve()
35
- }
26
+ @objc func sendResponse(_ call: CAPPluginCall) {
27
+ guard let requestId = call.getString("requestId") else {
28
+ call.reject("Missing requestId")
29
+ return
30
+ }
31
+
32
+ // Cast dictionaryRepresentation explicitly to [String: Any]
33
+ if let responseData = call.dictionaryRepresentation as? [String: Any] {
34
+ HttpLocalServerSwifter.handleJsResponse(requestId: requestId, responseData: responseData)
35
+ call.resolve()
36
+ } else {
37
+ call.reject("Could not parse response data")
38
+ }
39
+ }
36
40
 
37
41
  public func httpLocalServerSwifterDidReceiveRequest(_ data: [String: Any]) {
38
42
  notifyListeners("onRequest", data: data)
39
43
  }
40
- }
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cappitolian/http-local-server-swifter",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "Runs a local HTTP server on your device, accessible over LAN. Supports connect, disconnect, GET, and POST methods with IP and port discovery.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",