Skip to content

Commit 461771f

Browse files
committed
[js] saving
1 parent 00fc97c commit 461771f

File tree

5 files changed

+130
-1
lines changed

5 files changed

+130
-1
lines changed

JavaScript/from_json.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const Flatted = require("flatted");
2+
const asStr = '{"name":"test 3","prop":"2023-09-20T10:59:37.118Z"}';
3+
const asJson = Flatted.parse(asStr);
4+
const obj = Flatted.fromJSON(asJson);
5+
console.log(`typeof(obj.name) = ${typeof(obj.name)}`);
6+
console.log(`typeof(obj.prop) = ${typeof(obj.prop)}`);

JavaScript/package-lock.json

Lines changed: 88 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaScript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"author": "",
1212
"license": "ISC",
1313
"dependencies": {
14+
"flatted": "^3.2.9",
1415
"nearley": "^2.19.0"
1516
}
1617
}

JavaScript/try-catch.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
try {
2+
console.log("Hello");
3+
throw "World";
4+
console.log("Universe");
5+
} catch (err) {
6+
console.log(err);
7+
}

nodejs/proxy-server.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const http = require('node:http');
2+
const net = require('node:net');
3+
const { URL } = require('node:url');
4+
5+
// Create an HTTP tunneling proxy
6+
const proxy = http.createServer((req, res) => {
7+
res.writeHead(200, { 'Content-Type': 'text/plain' });
8+
res.end('okay');
9+
});
10+
11+
proxy.on('connect', (req, clientSocket, head) => {
12+
console.log("connect", req.url);
13+
// Connect to an origin server
14+
const { port, hostname } = new URL(`http://${req.url}`);
15+
const serverSocket = net.connect(port || 80, hostname, () => {
16+
clientSocket.write('HTTP/1.1 200 Connection Established\r\n' +
17+
'Proxy-agent: Node.js-Proxy\r\n' +
18+
'\r\n');
19+
serverSocket.write(head);
20+
serverSocket.pipe(clientSocket);
21+
clientSocket.pipe(serverSocket);
22+
});
23+
});
24+
25+
// Now that proxy is running
26+
proxy.listen(1337, '127.0.0.1', () => {
27+
console.log("Listen");
28+
});

0 commit comments

Comments
 (0)