forked from nanjingboy/nvmw
-
Notifications
You must be signed in to change notification settings - Fork 16
/
check-registry.js
47 lines (36 loc) · 965 Bytes
/
check-registry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
const https = require("https");
const http = require("http");
function getReq(url) {
const port = parseInt(url.port);
if (url.protocol === "https:") {
return { client: https, port: port || 443 };
} else if (url.protocol === "http:") {
return { client: http, port: port || 80 };
} else {
return { client: https, port: 443 };
}
}
function check() {
const registry = process.argv[2];
const url = new URL(registry);
const { client, port } = getReq(url);
const options = {
hostname: url.host,
port,
path: "/optional-require",
method: "GET"
};
const req = client.request(options, res => {
console.log(`Checking npm registry ${registry} statusCode: ${res.statusCode}`);
res.on("data", () => {
process.exit(0);
});
});
req.on("error", error => {
console.error(`Checking npm registry ${registry} failed:`, error.message);
process.exit(1);
});
req.end();
}
check();