"use strict";
/*
 * ATTENTION: An "eval-source-map" devtool has been used.
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file with attached SourceMaps in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
self["webpackHotUpdate_N_E"]("middleware",{

/***/ "(middleware)/./src/middleware.ts":
/*!***************************!*\
  !*** ./src/middleware.ts ***!
  \***************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   config: () => (/* binding */ config),\n/* harmony export */   \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _clerk_nextjs_server__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @clerk/nextjs/server */ \"(middleware)/./node_modules/@clerk/nextjs/dist/esm/server/routeMatcher.js\");\n/* harmony import */ var _clerk_nextjs_server__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @clerk/nextjs/server */ \"(middleware)/./node_modules/@clerk/nextjs/dist/esm/server/clerkMiddleware.js\");\n/* harmony import */ var next_server__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! next/server */ \"(middleware)/./node_modules/next/dist/esm/api/server.js\");\n/* harmony import */ var _lib_admin_session__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @/lib/admin-session */ \"(middleware)/./src/lib/admin-session.ts\");\n\n\n\nconst isProtectedRoute = (0,_clerk_nextjs_server__WEBPACK_IMPORTED_MODULE_2__.createRouteMatcher)([\n    \"/dashboard(.*)\",\n    \"/onboarding(.*)\",\n    \"/api/publish(.*)\",\n    \"/api/upload(.*)\",\n    \"/api/user(.*)\"\n]);\nfunction isAdminRoute(pathname) {\n    return pathname.startsWith(\"/admin\") || pathname.startsWith(\"/api/admin\");\n}\nfunction getSubdomain(req) {\n    const host = req.headers.get(\"host\");\n    if (!host) return null;\n    const apex = \"testbed.mk\" || 0;\n    const portIndex = host.indexOf(\":\");\n    const hostname = portIndex !== -1 ? host.slice(0, portIndex) : host;\n    const reserved = [\n        \"www\",\n        \"coolify\",\n        \"mail\",\n        \"accounts\",\n        \"clerk\",\n        \"clk\",\n        \"clk2\",\n        \"clkmail\"\n    ];\n    if (hostname === apex || reserved.includes(hostname) || hostname === `www.${apex}`) return null;\n    if (hostname.endsWith(`.${apex}`)) {\n        const sub = hostname.slice(0, hostname.length - apex.length - 1);\n        if (sub && !reserved.includes(sub)) return sub;\n    }\n    return null;\n}\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_clerk_nextjs_server__WEBPACK_IMPORTED_MODULE_3__.clerkMiddleware)(async (auth, req)=>{\n    if (isAdminRoute(req.nextUrl.pathname)) {\n        if (req.nextUrl.pathname === \"/admin/login\") {\n            return next_server__WEBPACK_IMPORTED_MODULE_0__.NextResponse.next();\n        }\n        const token = req.cookies.get(_lib_admin_session__WEBPACK_IMPORTED_MODULE_1__.COOKIE_NAME_ADMIN)?.value;\n        if (!token || !await (0,_lib_admin_session__WEBPACK_IMPORTED_MODULE_1__.verifyAdminSession)(token)) {\n            if (req.nextUrl.pathname.startsWith(\"/api/\")) {\n                return next_server__WEBPACK_IMPORTED_MODULE_0__.NextResponse.json({\n                    error: \"Неавторизирано\"\n                }, {\n                    status: 401\n                });\n            }\n            return next_server__WEBPACK_IMPORTED_MODULE_0__.NextResponse.redirect(new URL(\"/admin/login\", req.url));\n        }\n        return next_server__WEBPACK_IMPORTED_MODULE_0__.NextResponse.next();\n    }\n    if (isProtectedRoute(req)) {\n        await auth.protect();\n    }\n    const subdomain = getSubdomain(req);\n    if (subdomain && !req.nextUrl.pathname.startsWith(\"/api\")) {\n        const url = req.nextUrl.clone();\n        url.pathname = `/${subdomain}${url.pathname === \"/\" ? \"\" : url.pathname}`;\n        return next_server__WEBPACK_IMPORTED_MODULE_0__.NextResponse.rewrite(url);\n    }\n    return next_server__WEBPACK_IMPORTED_MODULE_0__.NextResponse.next();\n}));\nconst config = {\n    matcher: [\n        \"/(api|trpc)(.*)\",\n        \"/__clerk/:path*\",\n        \"/((?!_next|api/static|.*\\\\..*).*)\"\n    ]\n};\n//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 6368 characters]\n//# sourceURL=webpack-internal:///(middleware)/./src/middleware.ts\n");

/***/ })

});