class

Noir::JSHttpRouteExtractor

Inherits Reference < Object

Extracts routes from direct Node.js core http/https createServer handlers.

This covers the stdlib shape where applications branch on req.method and req.url/pathname inside a single request listener, rather than registering routes through a framework DSL.

Constants

ARROW_HEAD = /\G\s*(?:async\s*)?(?:(\()|([A-Za-z_$][\w$]*)\s*=>)/

(req: Request): Promise<Response> => / async req => read forward from the head: a backward walk from => stops at a TypeScript return type instead of the parameter list.

HTTP_METHODS = Set {"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE", "QUERY"}
RUNTIME_SERVE_CALLS = {"Bun" => /\bBun\s*\.\s*serve\s*\(/, "Deno" => /\bDeno\s*\.\s*serve\s*\(/}

Bun.serve(...) / Deno.serve(...) call openers, keyed by runtime.

SOURCE_EXTENSIONS = [".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".tsx"]
URL_PATTERN_DECL = /(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*new\s+URLPattern\s*\(\s*(?:\{\s*pathname\s*:\s*)?(['"`])(\/[^'"`]*)\2/

const NAME = new URLPattern({ pathname: "/p" }) or new URLPattern("/p").

Class methods

extract(file_path : String, content : String, debug : Bool = false) : Array(Endpoint)
Source
extract_fetch_request_params(body : String, endpoint : Endpoint) : Nil

Query and body params a Fetch-API / node:http handler reads from a request spelled req: searchParams.get("q"), URLSearchParams, JSON.parse(...), await req.json() / req.formData(). Shared with the file-routed serverless adapters, which normalize their request name to req first.

Source
extract_runtime_serve(file_path : String, content : String, runtime : String, debug : Bool = false) : Array(Endpoint)

Runtime-native servers: Bun.serve({ routes, fetch }) and Deno.serve(handler) / Deno.serve(options, handler) / Deno.serve({ handler }). The fetch handler body branches on req.method / new URL(req.url).pathname exactly like a createServer listener, so it goes through the same route-hit scan; Bun's routes map is read key by key.

Source
source_file?(file_path : String) : Bool
Source

Nested types