Skip to content

Commit

Permalink
feat(url): adapt http driver for loadFromUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Monnet committed Jan 30, 2025
1 parent 88f41ab commit b6cd98d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/drivers/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ import { joinURL } from "ufo";

export interface HTTPOptions {
base: string;
scheme?: string;
headers?: Record<string, string>;
}

const DRIVER_NAME = "http";

export default defineDriver((opts: HTTPOptions) => {
const r = (key: string = "") => joinURL(opts.base!, key.replace(/:/g, "/"));
const base =
opts.base.startsWith("//") && opts.scheme
? `${opts.scheme}:${opts.base}`
: opts.base;

const r = (key: string = "") => joinURL(base!, key.replace(/:/g, "/"));

const rBase = (key: string = "") =>
joinURL(opts.base!, (key || "/").replace(/:/g, "/"), ":");
joinURL(base!, (key || "/").replace(/:/g, "/"), ":");

const catchFetchError = (error: FetchError, fallbackVal: any = null) => {
if (error?.response?.status === 404) {
Expand Down

0 comments on commit b6cd98d

Please sign in to comment.