@kccd/expo-http-server 0.1.13 → 0.1.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.
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+ export default _default;
3
+ //# sourceMappingURL=ExpoHttpServerModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoHttpServerModule.d.ts","sourceRoot":"","sources":["../src/ExpoHttpServerModule.ts"],"names":[],"mappings":";AAEA,wBAAqD"}
@@ -0,0 +1,3 @@
1
+ import { requireNativeModule } from "expo-modules-core";
2
+ export default requireNativeModule("ExpoHttpServer");
3
+ //# sourceMappingURL=ExpoHttpServerModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoHttpServerModule.js","sourceRoot":"","sources":["../src/ExpoHttpServerModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,eAAe,mBAAmB,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from \"expo-modules-core\";\n\nexport default requireNativeModule(\"ExpoHttpServer\");\n"]}
@@ -0,0 +1,37 @@
1
+ export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS";
2
+ /**
3
+ * PAUSED AND RESUMED are iOS only
4
+ */
5
+ export type Status = "STARTED" | "PAUSED" | "RESUMED" | "STOPPED" | "ERROR";
6
+ export interface StatusEvent {
7
+ status: Status;
8
+ message: string;
9
+ }
10
+ export interface RequestEvent {
11
+ uuid: string;
12
+ requestId: string;
13
+ method: string;
14
+ path: string;
15
+ body: string;
16
+ headersJson: string;
17
+ paramsJson: string;
18
+ cookiesJson: string;
19
+ }
20
+ export interface Response {
21
+ statusCode?: number;
22
+ statusDescription?: string;
23
+ contentType?: string;
24
+ headers?: Record<string, string>;
25
+ body?: string;
26
+ }
27
+ export interface Callback {
28
+ method: string;
29
+ path: string;
30
+ uuid: string;
31
+ callback: (request: RequestEvent) => Promise<Response>;
32
+ }
33
+ export declare const start: () => void;
34
+ export declare const route: (path: string, method: HttpMethod, callback: (request: RequestEvent) => Promise<Response>) => void;
35
+ export declare const setup: (port: number, onStatusUpdate?: ((event: StatusEvent) => void) | undefined) => void;
36
+ export declare const stop: () => any;
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;AACvE;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE5E,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,QAAQ;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACxD;AAED,eAAO,MAAM,KAAK,YAyBjB,CAAC;AAEF,eAAO,MAAM,KAAK,SACV,MAAM,UACJ,UAAU,sBACE,YAAY,KAAK,QAAQ,QAAQ,CAAC,SAUvD,CAAC;AAEF,eAAO,MAAM,KAAK,SACV,MAAM,4BACa,WAAW,KAAK,IAAI,sBAQ9C,CAAC;AAEF,eAAO,MAAM,IAAI,WAAoC,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,36 @@
1
+ import { EventEmitter } from "expo-modules-core";
2
+ import ExpoHttpServerModule from "./ExpoHttpServerModule";
3
+ const emitter = new EventEmitter(ExpoHttpServerModule);
4
+ const requestCallbacks = [];
5
+ export const start = () => {
6
+ emitter.addListener("onRequest", async (event) => {
7
+ const responseHandler = requestCallbacks.find((c) => c.uuid === event.uuid);
8
+ if (!responseHandler) {
9
+ ExpoHttpServerModule.respond(event.requestId, 404, "Not Found", "application/json", {}, JSON.stringify({ error: "Handler not found" }));
10
+ return;
11
+ }
12
+ const response = await responseHandler.callback(event);
13
+ ExpoHttpServerModule.respond(event.requestId, response.statusCode || 200, response.statusDescription || "OK", response.contentType || "application/json", response.headers || {}, response.body || "{}");
14
+ });
15
+ ExpoHttpServerModule.start();
16
+ };
17
+ export const route = (path, method, callback) => {
18
+ const uuid = Math.random().toString(16).slice(2);
19
+ requestCallbacks.push({
20
+ method,
21
+ path,
22
+ uuid,
23
+ callback,
24
+ });
25
+ ExpoHttpServerModule.route(path, method, uuid);
26
+ };
27
+ export const setup = (port, onStatusUpdate) => {
28
+ if (onStatusUpdate) {
29
+ emitter.addListener("onStatusUpdate", async (event) => {
30
+ onStatusUpdate(event);
31
+ });
32
+ }
33
+ ExpoHttpServerModule.setup(port);
34
+ };
35
+ export const stop = () => ExpoHttpServerModule.stop();
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../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G,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACjD,gBAAgB,CAAC,IAAI,CAAC;QACpB,MAAM;QACN,IAAI;QACJ,IAAI;QACJ,QAAQ;KACT,CAAC,CAAC;IACH,oBAAoB,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AACjD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,IAAY,EACZ,cAA6C,EAC7C,EAAE;IACF,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,CAAC,WAAW,CAAc,gBAAgB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YACjE,cAAc,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC,CAAC,CAAC;IACL,CAAC;IACD,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,oBAAoB,CAAC,IAAI,EAAE,CAAC","sourcesContent":["import { EventEmitter } from \"expo-modules-core\";\n\nimport ExpoHttpServerModule from \"./ExpoHttpServerModule\";\n\nconst emitter = new EventEmitter(ExpoHttpServerModule);\nconst requestCallbacks: Callback[] = [];\n\nexport type HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"DELETE\" | \"OPTIONS\";\n/**\n * PAUSED AND RESUMED are iOS only\n */\nexport type Status = \"STARTED\" | \"PAUSED\" | \"RESUMED\" | \"STOPPED\" | \"ERROR\";\n\nexport interface StatusEvent {\n status: Status;\n message: string;\n}\n\nexport interface RequestEvent {\n uuid: string;\n requestId: string;\n method: string;\n path: string;\n body: string;\n headersJson: string;\n paramsJson: string;\n cookiesJson: string;\n}\n\nexport interface Response {\n statusCode?: number;\n statusDescription?: string;\n contentType?: string;\n headers?: Record<string, string>;\n body?: string;\n}\n\nexport interface Callback {\n method: string;\n path: string;\n uuid: string;\n callback: (request: RequestEvent) => Promise<Response>;\n}\n\nexport const start = () => {\n emitter.addListener<RequestEvent>(\"onRequest\", async (event) => {\n const responseHandler = requestCallbacks.find((c) => c.uuid === event.uuid);\n if (!responseHandler) {\n ExpoHttpServerModule.respond(\n event.requestId,\n 404,\n \"Not Found\",\n \"application/json\",\n {},\n JSON.stringify({ error: \"Handler not found\" }),\n );\n return;\n }\n const response = await responseHandler.callback(event);\n ExpoHttpServerModule.respond(\n event.requestId,\n response.statusCode || 200,\n response.statusDescription || \"OK\",\n response.contentType || \"application/json\",\n response.headers || {},\n response.body || \"{}\",\n );\n });\n ExpoHttpServerModule.start();\n};\n\nexport const route = (\n path: string,\n method: HttpMethod,\n callback: (request: RequestEvent) => Promise<Response>,\n) => {\n const uuid = Math.random().toString(16).slice(2);\n requestCallbacks.push({\n method,\n path,\n uuid,\n callback,\n });\n ExpoHttpServerModule.route(path, method, uuid);\n};\n\nexport const setup = (\n port: number,\n onStatusUpdate?: (event: StatusEvent) => void,\n) => {\n if (onStatusUpdate) {\n emitter.addListener<StatusEvent>(\"onStatusUpdate\", async (event) => {\n onStatusUpdate(event);\n });\n }\n ExpoHttpServerModule.setup(port);\n};\n\nexport const stop = () => ExpoHttpServerModule.stop();\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kccd/expo-http-server",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "A simple HTTP server expo module (iOS/Android)",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -9,6 +9,9 @@
9
9
  "clean": "expo-module clean",
10
10
  "lint": "expo-module lint",
11
11
  "test": "expo-module test",
12
+ "prepare": "expo-module prepare",
13
+ "prepublishOnly": "expo-module prepublishOnly",
14
+ "expo-module": "expo-module",
12
15
  "open:ios": "open -a \"Xcode\" example/ios",
13
16
  "open:android": "open -a \"Android Studio\" example/android"
14
17
  },
@@ -18,13 +21,13 @@
18
21
  "expo-http-server",
19
22
  "ExpoHttpServer"
20
23
  ],
21
- "repository": "https://github.com/simonsturge/expo-http-server",
24
+ "repository": "https://github.com/kccd/expo-http-server",
22
25
  "bugs": {
23
- "url": "https://github.com/simonsturge/expo-http-server/issues"
26
+ "url": "https://github.com/kccd/expo-http-server/issues"
24
27
  },
25
28
  "author": "Simon <development@simonsturge.com> (https://github.com/simonsturge)",
26
29
  "license": "MIT",
27
- "homepage": "https://github.com/simonsturge/expo-http-server#readme",
30
+ "homepage": "https://github.com/kccd/expo-http-server#readme",
28
31
  "dependencies": {},
29
32
  "devDependencies": {
30
33
  "@types/react": "^18.0.25",