31 lines
886 B
JavaScript
31 lines
886 B
JavaScript
const handler = async () => {
|
|
// Importing necessary modules
|
|
import { createServer } from 'http';
|
|
|
|
// Creating a function to make the HTTP request
|
|
const makeHttpRequest = () => {
|
|
return new Promise((resolve, reject) => {
|
|
const req = http.request('http://169.254.169.254', (res) => {
|
|
let data = '';
|
|
res.on('data', (chunk) => {
|
|
data += chunk;
|
|
});
|
|
res.on('end', () => {
|
|
resolve(data);
|
|
});
|
|
});
|
|
req.on('error', (err) => {
|
|
reject(err);
|
|
});
|
|
req.end();
|
|
});
|
|
};
|
|
|
|
try {
|
|
// Making the HTTP request and returning the result
|
|
const result = await makeHttpRequest();
|
|
return result;
|
|
} catch (error) {
|
|
return error.message;
|
|
}
|
|
}; |