expo-http-server 0.1.5 → 0.1.7
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.
- package/README.md +0 -2
- package/ios/ExpoHttpServerModule.swift +27 -22
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,8 +14,6 @@ iOS: [Criollo](https://github.com/thecatalinstan/Criollo)
|
|
|
14
14
|
Android: [AndroidServer](https://github.com/fengzhizi715/AndroidServer)
|
|
15
15
|
Web: **Not implemented**
|
|
16
16
|
|
|
17
|
-
This is a work in progress and not yet used in a production app (there are surely things I've overlooked), but please do make a PR for any improvements / problems you can see!
|
|
18
|
-
|
|
19
17
|
## Install
|
|
20
18
|
|
|
21
19
|
```shell
|
|
@@ -35,22 +35,24 @@ public class ExpoHttpServerModule: Module {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
private func routeHandler(path: String, method: String) {
|
|
38
|
-
server.add(path, block: {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
server.add(path, block: { (req, res, next) in
|
|
39
|
+
DispatchQueue.main.async {
|
|
40
|
+
let uuid = UUID().uuidString
|
|
41
|
+
var bodyString = "{}"
|
|
42
|
+
if let body = req.body, let bodyData = try? JSONSerialization.data(withJSONObject: body) {
|
|
43
|
+
bodyString = String(data: bodyData, encoding: .utf8) ?? "{}"
|
|
44
|
+
}
|
|
45
|
+
self.responses[uuid] = res
|
|
46
|
+
self.sendEvent("onRequest", [
|
|
47
|
+
"uuid": uuid,
|
|
48
|
+
"method": req.method.toString(),
|
|
49
|
+
"path": path,
|
|
50
|
+
"body": bodyString,
|
|
51
|
+
"headersJson": req.allHTTPHeaderFields.jsonString,
|
|
52
|
+
"paramsJson": req.query.jsonString,
|
|
53
|
+
"cookiesJson": req.cookies?.jsonString ?? "{}"
|
|
54
|
+
])
|
|
43
55
|
}
|
|
44
|
-
self?.sendEvent("onRequest", [
|
|
45
|
-
"uuid": uuid,
|
|
46
|
-
"method": req.method.toString(),
|
|
47
|
-
"path": path,
|
|
48
|
-
"body": bodyString,
|
|
49
|
-
"headersJson": req.allHTTPHeaderFields.jsonString,
|
|
50
|
-
"paramsJson": req.query.jsonString,
|
|
51
|
-
"cookiesJson": req.cookies?.jsonString ?? "{}"
|
|
52
|
-
])
|
|
53
|
-
self?.responses[uuid] = res
|
|
54
56
|
}, recursive: false, method: CRHTTPMethod.fromString(method))
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -58,13 +60,16 @@ public class ExpoHttpServerModule: Module {
|
|
|
58
60
|
statusCode: Int,
|
|
59
61
|
contentType: String,
|
|
60
62
|
body: String) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
DispatchQueue.main.async {
|
|
64
|
+
if let response = self.responses[udid] {
|
|
65
|
+
response.setStatusCode(UInt(statusCode), description: "ExpoHttpServer")
|
|
66
|
+
response.setValue(contentType, forHTTPHeaderField: "Content-type")
|
|
67
|
+
response.setValue("\(body.count)", forHTTPHeaderField: "Content-Length")
|
|
68
|
+
response.send(body);
|
|
69
|
+
self.responses[udid] = nil;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
private func stopHandler() {
|