@cappitolian/http-local-server 0.0.5 → 0.0.6
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/CappitolianHttpLocalServer.podspec +1 -1
- package/README.md +49 -91
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
|
|
|
11
11
|
s.author = package['author']
|
|
12
12
|
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
13
|
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
-
s.ios.deployment_target = '
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
15
|
s.dependency 'Capacitor'
|
|
16
16
|
s.swift_version = '5.1'
|
|
17
17
|
end
|
package/README.md
CHANGED
|
@@ -1,126 +1,84 @@
|
|
|
1
1
|
# @cappitolian/http-local-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Capacitor plugin to run a local HTTP server on your device, allowing you to receive and respond to HTTP requests directly from Angular/JavaScript.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
npm install @cappitolian/http-local-server
|
|
9
|
-
npx cap sync
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
## API
|
|
13
|
-
|
|
14
|
-
<docgen-index>
|
|
15
|
-
|
|
16
|
-
* [`connect()`](#connect)
|
|
17
|
-
* [`disconnect()`](#disconnect)
|
|
18
|
-
* [`sendResponse(...)`](#sendresponse)
|
|
19
|
-
* [`addListener('onRequest', ...)`](#addlisteneronrequest-)
|
|
20
|
-
* [`removeAllListeners()`](#removealllisteners)
|
|
21
|
-
* [Interfaces](#interfaces)
|
|
22
|
-
|
|
23
|
-
</docgen-index>
|
|
7
|
+
## Features
|
|
24
8
|
|
|
25
|
-
|
|
26
|
-
|
|
9
|
+
- Embed a real HTTP server (NanoHTTPD on Android, GCDWebServer on iOS).
|
|
10
|
+
- Receive requests via events and send responses back from the JS layer.
|
|
11
|
+
- CORS support enabled by default for local communication.
|
|
12
|
+
- Tested with **Capacitor 7** and **Ionic 8**.
|
|
27
13
|
|
|
28
|
-
|
|
14
|
+
---
|
|
29
15
|
|
|
30
|
-
|
|
31
|
-
connect() => Promise<HttpConnectResult>
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Inicia el servidor local en el dispositivo nativo.
|
|
35
|
-
Devuelve la IP y el puerto asignado.
|
|
36
|
-
|
|
37
|
-
**Returns:** <code>Promise<<a href="#httpconnectresult">HttpConnectResult</a>></code>
|
|
16
|
+
## Installation
|
|
38
17
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### disconnect()
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
disconnect() => Promise<void>
|
|
18
|
+
```bash
|
|
19
|
+
npm install @cappitolian/http-local-server
|
|
20
|
+
npx cap sync
|
|
46
21
|
```
|
|
47
22
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
--------------------
|
|
23
|
+
---
|
|
51
24
|
|
|
25
|
+
## Usage
|
|
52
26
|
|
|
53
|
-
###
|
|
27
|
+
### Import
|
|
54
28
|
|
|
55
29
|
```typescript
|
|
56
|
-
|
|
30
|
+
import { HttpLocalServer } from '@cappitolian/http-local-server';
|
|
57
31
|
```
|
|
58
32
|
|
|
59
|
-
|
|
60
|
-
El requestId debe coincidir con el recibido en 'onRequest'.
|
|
61
|
-
|
|
62
|
-
| Param | Type |
|
|
63
|
-
| ------------- | ------------------------------------------------- |
|
|
64
|
-
| **`options`** | <code>{ requestId: string; body: string; }</code> |
|
|
65
|
-
|
|
66
|
-
--------------------
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
### addListener('onRequest', ...)
|
|
33
|
+
### Listen and Respond
|
|
70
34
|
|
|
71
35
|
```typescript
|
|
72
|
-
|
|
36
|
+
// 1. Set up the listener for incoming requests
|
|
37
|
+
HttpLocalServer.addListener('onRequest', async (request) => {
|
|
38
|
+
console.log('Request received:', request.path, request.body);
|
|
39
|
+
|
|
40
|
+
// 2. Send a response back to the client using the requestId
|
|
41
|
+
await HttpLocalServer.sendResponse({
|
|
42
|
+
requestId: request.requestId,
|
|
43
|
+
body: JSON.stringify({ message: "Hello from Ionic!" })
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// 3. Start the server
|
|
48
|
+
HttpLocalServer.connect().then(result => {
|
|
49
|
+
console.log('Server running at:', result.ip, 'Port:', result.port);
|
|
50
|
+
});
|
|
73
51
|
```
|
|
74
52
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
| Param | Type |
|
|
78
|
-
| ------------------ | ------------------------------------------------------------------------------ |
|
|
79
|
-
| **`eventName`** | <code>'onRequest'</code> |
|
|
80
|
-
| **`listenerFunc`** | <code>(data: <a href="#httprequestdata">HttpRequestData</a>) => void</code> |
|
|
81
|
-
|
|
82
|
-
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>></code>
|
|
83
|
-
|
|
84
|
-
--------------------
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
### removeAllListeners()
|
|
53
|
+
### Stop Server
|
|
88
54
|
|
|
89
55
|
```typescript
|
|
90
|
-
|
|
56
|
+
HttpLocalServer.disconnect()
|
|
91
57
|
```
|
|
92
58
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
--------------------
|
|
96
|
-
|
|
59
|
+
---
|
|
97
60
|
|
|
98
|
-
|
|
61
|
+
## Platforms
|
|
99
62
|
|
|
63
|
+
- **iOS** (Swift)
|
|
64
|
+
- **Android** (Java)
|
|
65
|
+
- **Web** (Returns mock values for development)
|
|
100
66
|
|
|
101
|
-
|
|
67
|
+
---
|
|
102
68
|
|
|
103
|
-
|
|
104
|
-
| ---------- | ------------------- |
|
|
105
|
-
| **`ip`** | <code>string</code> |
|
|
106
|
-
| **`port`** | <code>number</code> |
|
|
69
|
+
## Requirements
|
|
107
70
|
|
|
71
|
+
- [Capacitor 7](https://capacitorjs.com/)
|
|
72
|
+
- [Ionic 8](https://ionicframework.com/) (optional, but tested)
|
|
108
73
|
|
|
109
|
-
|
|
74
|
+
---
|
|
110
75
|
|
|
111
|
-
|
|
112
|
-
| ------------ | ----------------------------------------- |
|
|
113
|
-
| **`remove`** | <code>() => Promise<void></code> |
|
|
76
|
+
## License
|
|
114
77
|
|
|
78
|
+
MIT
|
|
115
79
|
|
|
116
|
-
|
|
80
|
+
---
|
|
117
81
|
|
|
118
|
-
|
|
119
|
-
| --------------- | ------------------- |
|
|
120
|
-
| **`requestId`** | <code>string</code> |
|
|
121
|
-
| **`method`** | <code>string</code> |
|
|
122
|
-
| **`path`** | <code>string</code> |
|
|
123
|
-
| **`body`** | <code>string</code> |
|
|
124
|
-
| **`headers`** | <code>any</code> |
|
|
82
|
+
## Support
|
|
125
83
|
|
|
126
|
-
|
|
84
|
+
If you have any issues or feature requests, please open an issue on the repository.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappitolian/http-local-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
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",
|