"use strict";
/**
 * A library for mounting different `fetch` handlers on
 * URL pathnames.
 *
 * @preferred
 * @module fly/fetch/mount
 */
Object.defineProperty(exports, "__esModule", { value: true });
const _1 = require(".");
/**
 * Mount different handlers on URL paths. Example:
 *
 * ```javascript
 * import { mount } from "@fly/fetch/mount"
 * const mounts = mount({
 *  "/hello/": (req, init) => new Response("hello")
 *  "/": (req, init) => new Response("index")
 * })
 *
 * fly.http.respondWith(mounts)
 * ```
 */
function mount(paths) {
    return async function mountFetch(req, init) {
        req = _1.normalizeRequest(req);
        const url = new URL(req.url);
        for (const p of Object.getOwnPropertyNames(paths)) {
            if (url.pathname.startsWith(p)) {
                return paths[p](req, init);
            }
        }
        return new Response("no mount found", { status: 404 });
    };
}
exports.mount = mount;
exports.default = mount;
//# sourceMappingURL=mount.js.map