WIP: check proxy on pages
This commit is contained in:
1 parent
8b07dfe30e
commit
6a7effe668
5 files changed
+27
-34
No files matched your search
@@ -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,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) })
|
||||
|
||||
Reference in new issue
Block a user