etherproxy-lite 0.1.0

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.
Files changed (2) hide show
  1. package/dist/index.js +54 -0
  2. package/package.json +23 -0
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const cafe_utility_1 = require("cafe-utility");
5
+ const http_1 = require("http");
6
+ const sequence = cafe_utility_1.Numbers.createSequence();
7
+ const hostname = cafe_utility_1.Arrays.requireStringArgument(process.argv, 'hostname');
8
+ const port = cafe_utility_1.Arrays.requireNumberArgument(process.argv, 'port');
9
+ const target = cafe_utility_1.Arrays.requireStringArgument(process.argv, 'target');
10
+ cafe_utility_1.System.forever(async () => {
11
+ cafe_utility_1.Cache.deleteExpired();
12
+ }, cafe_utility_1.Dates.seconds(2));
13
+ const server = (0, http_1.createServer)(async (request, response) => {
14
+ request.on('error', error => {
15
+ console.error(error);
16
+ });
17
+ response.on('error', error => {
18
+ console.error(error);
19
+ });
20
+ const chunks = [];
21
+ request.on('data', (chunk) => {
22
+ chunks.push(chunk);
23
+ });
24
+ request.on('end', async () => {
25
+ try {
26
+ const body = JSON.parse(Buffer.concat(chunks).toString('utf-8'));
27
+ const id = body.id;
28
+ delete body.id;
29
+ const key = JSON.stringify(body);
30
+ const promise = await cafe_utility_1.Cache.get(key, cafe_utility_1.Dates.seconds(2), async () => {
31
+ const init = {
32
+ method: 'POST',
33
+ signal: AbortSignal.timeout(cafe_utility_1.Dates.seconds(10)),
34
+ headers: { 'Content-Type': 'application/json' },
35
+ body: JSON.stringify({ ...body, id: sequence.next() })
36
+ };
37
+ return {
38
+ data: fetch(target, init)
39
+ .then(x => x.json())
40
+ .then(x => cafe_utility_1.Types.asObject(x))
41
+ };
42
+ });
43
+ const json = await promise.data;
44
+ response.end(JSON.stringify({ ...json, id }));
45
+ }
46
+ catch (error) {
47
+ console.error(error);
48
+ response.statusCode = 503;
49
+ response.end('503 Service Unavailable');
50
+ }
51
+ });
52
+ });
53
+ server.listen(port, hostname);
54
+ console.log(`Etherproxy-Lite is running on port ${hostname}:${port}`);
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "etherproxy-lite",
3
+ "version": "0.1.0",
4
+ "bin": {
5
+ "etherproxy-lite": "./dist/index.js"
6
+ },
7
+ "main": "dist/index.js",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "check": "tsc --noEmit"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "description": "",
16
+ "dependencies": {
17
+ "cafe-utility": "^33.3.2"
18
+ },
19
+ "devDependencies": {
20
+ "@types/node": "^24.10.0",
21
+ "typescript": "^5.9.3"
22
+ }
23
+ }