Adicionar src/main.mjs
This commit is contained in:
parent
1e163a9374
commit
5a4a8d62da
1 changed files with 84 additions and 0 deletions
84
src/main.mjs
Normal file
84
src/main.mjs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
import express from 'express';
|
||||
import bodyParser from 'body-parser';
|
||||
import cors from 'cors';
|
||||
import axios from 'axios';
|
||||
import { dentroHorarioExpediente } from './utils.mjs';
|
||||
|
||||
const PORT = 3000;
|
||||
|
||||
const app = express();
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
app.use(cors());
|
||||
|
||||
// Rota para verificar status do dispositivo
|
||||
app.get('/status/:serialNumber', async (req, res) => {
|
||||
if (!dentroHorarioExpediente()) {
|
||||
return res.status(200).json({
|
||||
error: "Fora do horário de expediente (07:30 - 17:30)",
|
||||
permitido: false
|
||||
});
|
||||
}
|
||||
|
||||
const { serialNumber } = req.params;
|
||||
let sendData = `tipo=verificarStatusEvo&sn=${serialNumber}`;
|
||||
|
||||
let config = {
|
||||
method: 'post',
|
||||
maxBodyLength: Infinity,
|
||||
url: 'https://ponteiro.online/Painel/Ajax',
|
||||
headers: {
|
||||
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
||||
'Accept-Language': 'pt-BR,pt;q=0.9',
|
||||
'Connection': 'keep-alive',
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
'Origin': 'https://ponteiro.online',
|
||||
'Referer': 'https://ponteiro.online/Painel/DispositivoFacial/GetColaboradores/AYTC09023967',
|
||||
'Sec-Fetch-Dest': 'empty',
|
||||
'Sec-Fetch-Mode': 'cors',
|
||||
'Sec-Fetch-Site': 'same-origin',
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'sec-ch-ua': '"Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99"',
|
||||
'sec-ch-ua-mobile': '?0',
|
||||
'sec-ch-ua-platform': '"Windows"',
|
||||
'Cookie': '_ga=GA1.2.1400579672.1762457415; _ga_CX37L3HT33=GS2.1.s1762517686$o2$g0$t1762517686$j60$l0$h0; PHPSESSID=55e0e1pes0u7hvida0eo9vgcf5; TawkConnectionTime=0; twk_uuid_5c87c6c4c37db86fcfcd5d3d=%7B%22uuid%22%3A%221.Ws3HlUz9SMuNtJ588HwbPzJoxT6Ym4uaMb2CeGR4vOCyNX03GtUb34AHmofIelEm6hiCzBPi89eDCX86ONCPS8NOzV3vKb4mzh5aV8aKL5EJJ8ibEkH4zsPka%22%2C%22version%22%3A3%2C%22domain%22%3A%22ponteiro.online%22%2C%22ts%22%3A1764702005679%7D; PHPSESSID=g2j2ktahk0ljcift84ultucl87'
|
||||
},
|
||||
data: sendData
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await axios.request(config);
|
||||
|
||||
const data = response.data;
|
||||
|
||||
if (data.ativo === true) {
|
||||
return res.status(200).json({
|
||||
status: 'online',
|
||||
sn: data.sn
|
||||
})
|
||||
}
|
||||
|
||||
if (data.ativo === false) {
|
||||
return res.status(503).json({
|
||||
status: 'offline',
|
||||
sn: data.sn
|
||||
})
|
||||
}
|
||||
|
||||
return res.status(500).json({
|
||||
error: 'Resposta inesperada da API externa',
|
||||
data
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Erro na API:", error);
|
||||
return res.status(500).json({
|
||||
error: "Erro ao consultar API externa",
|
||||
details: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`API rodando na porta ${PORT}`);
|
||||
});
|
||||
Loading…
Reference in a new issue