WIP: check proxy on pages

This commit is contained in:
lyc8503 committed 2025-04-12 22:20:33 +08:00
1 parent 8b07dfe30e
commit 6a7effe668
5 files changed
+27 -34

No files matched your search

-30
View File
@@ -8,36 +8,6 @@ export interface Env {
}
export default {
async fetch(request: Request): Promise<Response> {
const workerLocation = request.cf?.colo
console.log(`Handling request event at ${workerLocation}...`)
if (request.method !== 'POST') {
return new Response('Remote worker is working...', { status: 405 })
}
const targetId = (await request.json<{ target: string }>())['target']
const target = workerConfig.monitors.find((m) => m.id === targetId)
if (target === undefined) {
return new Response('Target Not Found', { status: 404 })
}
const status = await getStatus(target)
return new Response(
JSON.stringify({
location: workerLocation,
status: status,
}),
{
headers: {
'content-type': 'application/json;charset=UTF-8',
},
}
)
},
async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {
const workerLocation = (await getWorkerLocation()) || 'ERROR'
console.log(`Running scheduled event on ${workerLocation}...`)
+1 -1
View File
@@ -1,4 +1,3 @@
import { connect } from "cloudflare:sockets";
import { MonitorTarget } from "../../uptime.types";
import { withTimeout, fetchTimeout } from "./util";
@@ -16,6 +15,7 @@ export async function getStatus(
if (monitor.method === 'TCP_PING') {
// TCP port endpoint monitor
try {
const connect = await import(/* webpackIgnore: true */ "cloudflare:sockets").then((sockets) => sockets.connect)
// This is not a real https connection, but we need to add a dummy `https://` to parse the hostname & port
const parsed = new URL("https://" + monitor.target)
const socket = connect({ hostname: parsed.hostname, port: Number(parsed.port) })