Skip to content

Commit a117998

Browse files
committed
feat: add nodejs scripts to interact with http api
1 parent 08dce23 commit a117998

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585

8686
"node/no-unsupported-features": "error",
8787
"node/process-exit-as-throw": "error",
88-
"node/shebang": "warn",
88+
"node/shebang": "off",
8989
"node/no-deprecated-api": "warn",
9090
"no-useless-constructor": "warn",
9191
"no-return-await": "off"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
3+
async function ackDeprecatedImages() {
4+
try {
5+
const count = Number(process.argv[2]);
6+
if (Number.isNaN(count)) {
7+
console.error('Usage: node ./ack-deprecated-images.script.js <count>');
8+
process.exit(1);
9+
}
10+
11+
const URL = 'http://0.0.0.0:8080/deprecated-images/ack';
12+
13+
const response = await fetch(URL, {
14+
method: 'POST',
15+
headers: {
16+
'Content-Type': 'application/json'
17+
},
18+
body: JSON.stringify({ count }),
19+
});
20+
21+
if (!response.ok) {
22+
throw new Error(`Request failed with status ${response.status}`);
23+
}
24+
25+
const data = await response.json();
26+
console.log(JSON.stringify(data));
27+
} catch (error) {
28+
console.error('Error: ', error);
29+
process.exit(1);
30+
}
31+
}
32+
33+
ackDeprecatedImages();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env node
2+
3+
async function getDeprecatedImages() {
4+
try {
5+
const URL = 'http://0.0.0.0:8080/deprecated-images';
6+
7+
const response = await fetch(URL);
8+
if (!response.ok) {
9+
throw new Error(`Request failed with status ${response.status}`);
10+
}
11+
12+
const data = await response.json();
13+
console.log(JSON.stringify(data));
14+
} catch (error) {
15+
console.error('Error: ', error);
16+
process.exit(1);
17+
}
18+
}
19+
20+
getDeprecatedImages();

0 commit comments

Comments
 (0)