Spaces:
Running
Running
Download src/utils/http.ts from climateexploer/eurometeo: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/climateexploer/eurometeo/resolve/main/src/utils/http.ts
- Command line
-
hf download hf://spaces/climateexploer/eurometeo/src/utils/http.ts
-
curl -L -o http.ts https://huggingface.co/spaces/climateexploer/eurometeo/resolve/main/src/utils/http.ts
1.48 kB
| import https from "https"; | |
| /** | |
| * Perform a GET request bypassing SSL verification strictly for observations.meteogate.eu | |
| */ | |
| export function fetchBypassSSL(url: string, timeoutMs: number = 30000): Promise<string> { | |
| return new Promise((resolve, reject) => { | |
| const isMeteoGate = url.includes("meteogate.eu"); | |
| const agent = isMeteoGate ? new https.Agent({ rejectUnauthorized: false }) : undefined; | |
| const options: https.RequestOptions = { | |
| agent, | |
| headers: { | |
| "User-Agent": "EuroMeteo-NextJS/1.0", | |
| }, | |
| timeout: timeoutMs, | |
| }; | |
| const req = https.get(url, options, (res) => { | |
| if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { | |
| // Handle redirection | |
| fetchBypassSSL(res.headers.location, timeoutMs).then(resolve).catch(reject); | |
| return; | |
| } | |
| res.setEncoding("utf8"); | |
| let data = ""; | |
| res.on("data", (chunk) => { | |
| data += chunk; | |
| }); | |
| res.on("end", () => { | |
| if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) { | |
| resolve(data); | |
| } else { | |
| reject(new Error(`Request failed with status code ${res.statusCode}`)); | |
| } | |
| }); | |
| res.on("error", (err) => { | |
| reject(err); | |
| }); | |
| }); | |
| req.on("error", (err) => { | |
| reject(err); | |
| }); | |
| req.on("timeout", () => { | |
| req.destroy(); | |
| reject(new Error("Request timed out")); | |
| }); | |
| }); | |
| } | |