working on server registration

This commit is contained in:
2023-03-03 12:44:56 +01:00
parent 9165906e39
commit eac66702de
6 changed files with 141 additions and 17 deletions
+29
View File
@@ -0,0 +1,29 @@
import http from 'http'
import https from 'https'
export async function GetRequest(url: string) {
return new Promise<string>((resolve, reject) => {
let handler = (resp: http.IncomingMessage) => {
let data = ''
// A chunk of data has been received.
resp.on('data', (chunk) => {
data += chunk
})
// The whole response has been received. Print out the result.
resp.on('end', () => {
resolve(data)
})
resp.on('error', (err) => {
reject(err)
})
}
if (url.startsWith('https')) {
https.get(url, handler)
} else {
http.get(url, handler)
}
})
}