Está no ar?

Uma API para verificar se um site está no ar? Parece útil.

// Arquivo: src/index.js
import dotenv from 'dotenv';
import express from 'express';
import router from './routes.js';

dotenv.config();

const app = express();

app.use(express.json());
app.use(router);

const port = process.env.APP_PORT;
app.listen(port, () => {
    console.log(`Listening on: http://localhost:${port}`);
});
// Arquivo: src/routes.js
import { Router } from 'express';
import * as requestController from './controllers/request.js';

const router = Router();

router
    .post('/request', requestController.triggerRequest);

export default router;
// Arquivo: src/controllers/request.js
import axios from 'axios';

export async function triggerRequest(req, res) {
    let response;
    const config = req.body;

    try {
        response = await axios(config);
    } catch (e) {
        res
            .status(400)
            .json({
                message: `Failed to connect: ${e.message}`,
                data: e.response?.data,
            });

        return;
    }

    res
        .status(200)
        .json({
            status: response.status,
            body: response.data,
            headers: response.headers,
        });
}