just-another-http-api 1.4.2 → 1.4.4
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 +2 -0
- package/api.js +5 -2
- package/package.json +1 -1
- package/utils/WebsocketGroup.js +14 -3
package/README.md
CHANGED
|
@@ -90,6 +90,7 @@ The HTTP API module requires a configuration object to initialize. Here's a brea
|
|
|
90
90
|
- `jwtRefreshExpiresIn`: Expiry time for refresh tokens.
|
|
91
91
|
- `docRoot`: Directory containing route definitions.
|
|
92
92
|
- `port`: Port number for the server.
|
|
93
|
+
- `host`: Hostname/interface to bind the server to (e.g. `localhost`, `127.0.0.1`, `0.0.0.0`).
|
|
93
94
|
- `logs`: Enable or disable logging. Accepts a function or false.
|
|
94
95
|
- `uploads`: File upload configuration.
|
|
95
96
|
- `enabled`: Enable or disable file uploads.
|
|
@@ -113,6 +114,7 @@ const getConfig = async () => {
|
|
|
113
114
|
cache: {...}, // See Caching section for details
|
|
114
115
|
auth: {...}, // See Authentication section for details
|
|
115
116
|
docRoot: './routes', // This is where you store your endpoint handlers
|
|
117
|
+
host: 'localhost',
|
|
116
118
|
port: 4500,
|
|
117
119
|
logs: false, // Accepts function or false
|
|
118
120
|
uploads: {...}, // See Uploads section for details
|
package/api.js
CHANGED
|
@@ -18,7 +18,10 @@ module.exports = async ( config, _app = null ) => {
|
|
|
18
18
|
const endpoints = await loadEndpoints ( config );
|
|
19
19
|
endpoints.forEach ( endpoint => registerEndpoint ( app, endpoint, config ) );
|
|
20
20
|
|
|
21
|
-
await app.listen ( {
|
|
21
|
+
await app.listen ( {
|
|
22
|
+
host: process.env.HOST || config?.host || 'localhost',
|
|
23
|
+
port: process.env.PORT || config?.port || 4001
|
|
24
|
+
} );
|
|
22
25
|
|
|
23
26
|
return app;
|
|
24
27
|
};
|
|
@@ -306,4 +309,4 @@ const recursiveReadDir = async ( docRoot ) => {
|
|
|
306
309
|
console.error ( 'JustAnother: Failed to load your routes directory for generating endpoints.' );
|
|
307
310
|
throw e;
|
|
308
311
|
}
|
|
309
|
-
};
|
|
312
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "just-another-http-api",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "A framework built on top of fastify aimed at removing the need for any network or server configuration. ",
|
|
5
5
|
"homepage": "https://github.com/OllieEdge/just-another-http-api#readme",
|
|
6
6
|
"repository": {
|
package/utils/WebsocketGroup.js
CHANGED
|
@@ -46,8 +46,19 @@ class WebsocketGroup {
|
|
|
46
46
|
#pingConnections () {
|
|
47
47
|
this.connections.forEach ( ( connection, connectionId ) => {
|
|
48
48
|
if(!connection.isAlive) {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
try {
|
|
50
|
+
if ( typeof connection.terminate === 'function' ) {
|
|
51
|
+
connection.terminate ();
|
|
52
|
+
}
|
|
53
|
+
else if ( typeof connection.close === 'function' ) {
|
|
54
|
+
connection.close ();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch ( error ) {
|
|
58
|
+
console.error ( 'WebSocket ping cleanup error:', error );
|
|
59
|
+
this.connections.delete ( connectionId );
|
|
60
|
+
this.#clean ( connectionId );
|
|
61
|
+
}
|
|
51
62
|
}
|
|
52
63
|
else{
|
|
53
64
|
connection.isAlive = false;
|
|
@@ -121,4 +132,4 @@ class WebsocketGroup {
|
|
|
121
132
|
}
|
|
122
133
|
}
|
|
123
134
|
|
|
124
|
-
module.exports = WebsocketGroup;
|
|
135
|
+
module.exports = WebsocketGroup;
|