Add Vercel project with health check ping
Static frontend + Python serverless function at /api/ping that sends a GET request to Healthchecks.io and returns JSON status. https://claude.ai/code/session_01U8j5zqsX4kwqjnzq3EncSi
This commit is contained in:
commit
b32ef2082c
3 changed files with 69 additions and 0 deletions
24
api/ping.py
Normal file
24
api/ping.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import socket
|
||||||
|
import urllib.request
|
||||||
|
from http.server import BaseHTTPRequestHandler
|
||||||
|
|
||||||
|
PING_URL = "https://hc-ping.com/4f9a5abf-38d6-4f34-a698-9e97c3a62632"
|
||||||
|
|
||||||
|
|
||||||
|
def do_ping():
|
||||||
|
try:
|
||||||
|
urllib.request.urlopen(PING_URL, timeout=10)
|
||||||
|
return {"status": "ok", "message": "Ping sent successfully"}
|
||||||
|
except socket.error as e:
|
||||||
|
return {"status": "error", "message": f"Ping failed: {e}"}
|
||||||
|
|
||||||
|
|
||||||
|
class handler(BaseHTTPRequestHandler):
|
||||||
|
def do_GET(self):
|
||||||
|
result = do_ping()
|
||||||
|
body = str(result).encode()
|
||||||
|
self.send_response(200)
|
||||||
|
self.send_header("Content-Type", "application/json")
|
||||||
|
self.end_headers()
|
||||||
|
import json
|
||||||
|
self.wfile.write(json.dumps(result).encode())
|
||||||
40
index.html
Normal file
40
index.html
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="pt-BR">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Health Check Ping</title>
|
||||||
|
<style>
|
||||||
|
body { font-family: sans-serif; max-width: 600px; margin: 80px auto; padding: 0 20px; }
|
||||||
|
h1 { font-size: 1.5rem; }
|
||||||
|
button {
|
||||||
|
background: #000; color: #fff; border: none;
|
||||||
|
padding: 10px 24px; border-radius: 6px; cursor: pointer; font-size: 1rem;
|
||||||
|
}
|
||||||
|
button:hover { background: #333; }
|
||||||
|
#result { margin-top: 20px; padding: 16px; background: #f4f4f4; border-radius: 6px; display: none; }
|
||||||
|
.ok { color: green; } .error { color: red; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Health Check Ping</h1>
|
||||||
|
<p>Clique no botão para enviar um ping ao Healthchecks.io.</p>
|
||||||
|
<button onclick="sendPing()">Enviar Ping</button>
|
||||||
|
<div id="result"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
async function sendPing() {
|
||||||
|
const el = document.getElementById('result');
|
||||||
|
el.style.display = 'block';
|
||||||
|
el.innerHTML = 'Enviando...';
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/ping');
|
||||||
|
const data = await res.json();
|
||||||
|
el.innerHTML = `<span class="${data.status}">${data.message}</span>`;
|
||||||
|
} catch (e) {
|
||||||
|
el.innerHTML = `<span class="error">Erro: ${e.message}</span>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
5
vercel.json
Normal file
5
vercel.json
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"rewrites": [
|
||||||
|
{ "source": "/api/ping", "destination": "/api/ping.py" }
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue