diff --git a/src/entities/http-for-dummies.ts b/src/entities/http-for-dummies.ts index 1631995..a98f4d5 100644 --- a/src/entities/http-for-dummies.ts +++ b/src/entities/http-for-dummies.ts @@ -1,4 +1,18 @@ +/** + * Some HTTP-related utilities. + */ + import { ProjectRequestSpec } from "@/entities/project-entities"; +import { RequestSnapshot } from "./runtime-entities"; + +export function isRequestingToLocalhost(request: RequestSnapshot): boolean { + return [ + "http://localhost", + "https://localhost", + "http://127.0.0.1", + "https://127.0.0.1", + ].some((localBeginning) => request.url.startsWith(localBeginning)); +} /** HTTP methods but as constants. */ export const HTTP_METHODS: Array = [ diff --git a/src/features/project-workspace/Runtime.tsx b/src/features/project-workspace/Runtime.tsx index 4afdb4a..ecece4d 100644 --- a/src/features/project-workspace/Runtime.tsx +++ b/src/features/project-workspace/Runtime.tsx @@ -12,6 +12,7 @@ import { ResponseSnapshot, RuntimeState, } from "@/entities/runtime-entities"; +import { Anchor } from "@/components/ui/typography"; import { Select, SelectContent, @@ -27,12 +28,12 @@ import { CollapsibleTrigger, } from "@/components/ui/collapsible"; import { Progress } from "@/components/ui/progress"; -import { useRequestsSpecs } from "./RequestsSpecsContext"; import { HTTP_METHODS, getMethodExplanation, getStatusExplanation, getStatusText, + isRequestingToLocalhost, } from "../../entities/http-for-dummies"; import { cn } from "@/lib/utils"; import { @@ -41,6 +42,7 @@ import { DialogHeader, DialogTitle, } from "@/components/ui/dialog"; +import { useRequestsSpecs } from "./RequestsSpecsContext"; export interface RuntimeProps { specUuid: ProjectRequestSpec["uuid"]; @@ -229,7 +231,7 @@ export function Runtime(props: RuntimeProps) {

Error

{runtime.errorMessage ? ( -

+

Browser reason:{" "} {runtime.errorMessage}

@@ -238,7 +240,22 @@ export function Runtime(props: RuntimeProps) { For unknown reasons.

)} -

+ {isRequestingToLocalhost(runtime.request) && ( +

+ + 💡 + + You're requesting localhost, it can be a classic{" "} + + CORS policy + {" "} + issue. +

+ )} +

This specific error was thrown by your own browser, not exactly the server.