{"version":3,"file":"astro.mjs","sources":["../out/main.js"],"sourcesContent":["// imports here\nimport { bs, enhanceIncomingMessage, enhanceServerResponse, } from \"@bs-core/shell\";\nimport { App } from \"astro/app\";\nimport { pathToFileURL } from \"url\";\n// Misc consts here\nconst ADAPTER_NAME = \"@bs-core/astro\";\nconst ADAPTER_LATENCY_NAME = \"astro\";\n// Module properties here\nlet _app;\n// Private functions here\nfunction matcher(_) {\n    return (url) => {\n        const routeData = _app.match(new Request(url));\n        if (routeData === undefined) {\n            return false;\n        }\n        // For now we will ignore the params because they are available\n        // in the Web Request object\n        // NOTE: We need to return routeData so it can be use with _app.render()\n        return {\n            params: {},\n            matchedInfo: routeData,\n        };\n    };\n}\nasync function render(webReq) {\n    return await _app.render(webReq, {\n        routeData: webReq.req.matchedInfo,\n    });\n}\n// Exported functions here\n// The default function is called when the bundle script is being built\nexport default (config) => {\n    return {\n        name: ADAPTER_NAME,\n        hooks: {\n            \"astro:config:done\": ({ setAdapter }) => {\n                setAdapter({\n                    name: ADAPTER_NAME,\n                    serverEntrypoint: \"@bs-core/astro\",\n                    // previewEntrypoint: '@bs-core/astro',\n                    args: config,\n                    exports: [],\n                    supportedAstroFeatures: {\n                        hybridOutput: \"stable\",\n                        staticOutput: \"stable\",\n                        serverOutput: \"stable\",\n                        assets: {\n                            supportKind: \"stable\",\n                            isSharpCompatible: false,\n                            isSquooshCompatible: false,\n                        },\n                    },\n                });\n            },\n            \"astro:build:done\": async () => {\n                // We could update the bundle file here if needed\n            },\n            \"astro:server:setup\": async ({ server }) => {\n                // This is called when running the app in \"dev\" mode\n                // Set the adapter name to use in the latency measurements\n                config.httpConfig.ssrServer = {\n                    adapterName: ADAPTER_LATENCY_NAME,\n                };\n                // We need the req handler from the HttpServer so lets create one\n                // even though we will not actually use it directly\n                const httpServer = await bs.addHttpServer(config.httpConfig, false);\n                // Call setupEntryPoint in case they want to setup add API endpoints\n                if (config.setupEntryPoint !== undefined) {\n                    // NOTE: We expect an exported function named \"setup\"\n                    const { setup } = await import(pathToFileURL(config.setupEntryPoint).href);\n                    await setup();\n                }\n                bs.startupMsg(\"HTTP server has been created\");\n                // Add the req handler to the dev server middleware\n                server.middlewares.use(async (req, res, next) => {\n                    // Enhance req/res so that the endpoint code with work correctly\n                    let enhancedReq = enhanceIncomingMessage(req);\n                    let enhancedRes = enhanceServerResponse(res);\n                    // We only want the reeq handler to handle API reqs\n                    enhancedReq.checkSsrRoutes = false;\n                    enhancedReq.checkStaticFiles = false;\n                    // Make sure we do not generate a 404 if the route is not found\n                    enhancedReq.handle404 = false;\n                    // Call our req handler\n                    await httpServer.reqHandler(enhancedReq, enhancedRes);\n                    // If the req was handled by the req handler then we are done\n                    if (enhancedReq.handled) {\n                        return;\n                    }\n                    // If we are here the req was not handled, so call next\n                    next();\n                });\n            },\n        },\n    };\n};\n// We need a createExports() exported or Astro will complain\nexport const createExports = () => {\n    return {};\n};\n// This function that will be called when the bundled script is run\nexport const start = async (manifest, config) => {\n    // Create the app first before doing anything else\n    _app = new App(manifest);\n    config.httpConfig.ssrServer = {\n        ...config.httpConfig.ssrServer,\n        adapterName: ADAPTER_LATENCY_NAME,\n        render,\n        matcher,\n    };\n    // We need the req handler from the HttpServer so lets create one\n    // even though we will not actually use it directly\n    const httpServer = await bs.addHttpServer(config.httpConfig, false);\n    // Call setupEntryPoint here in case you want to setup any default\n    // middleware for the SSR endpoint or add API endpoints\n    if (config.setupEntryPoint !== undefined) {\n        // NOTE: We expect an exported function named \"setup\"\n        const { setup } = await import(pathToFileURL(config.setupEntryPoint).href);\n        await setup();\n    }\n    // Start the http server now!\n    await httpServer.start();\n    bs.startupMsg(\"Astro adapter is primed - party on dudes!!\");\n};\n//# sourceMappingURL=main.js.map"],"names":[],"mappings":";;;;AAAA;AAIA;AACA,MAAM,YAAY,GAAG,gBAAgB;AACrC,MAAM,oBAAoB,GAAG,OAAO;AACpC;AACA,IAAI,IAAI;AACR;AACA,SAAS,OAAO,CAAC,CAAC,EAAE;AACpB,IAA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