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';
.config();
dotenv
const app = express();
.use(express.json());
app.use(router);
app
const port = process.env.APP_PORT;
.listen(port, () => {
appconsole.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 {
= await axios(config);
response 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,
;
}) }