/**
 * Minified by jsDelivr using Terser v5.48.0.
 * Original file: /npm/@cedarjs/api-server@7.1.0/dist/createServer.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import fs from"node:fs";import path from"node:path";import{pathToFileURL}from"node:url";import ansis from"ansis";import{config}from"dotenv-defaults";import fg from"fast-glob";import fastify from"fastify";import{getAsyncStoreInstance}from"@cedarjs/context/dist/store";import{getConfig,getPaths}from"@cedarjs/project-config";import{resolveOptions}from"./createServerHelpers.js";import{cedarFastifyAPI}from"./plugins/api.js";async function createServer(e={}){const{apiRootPath:r,fastifyServerOptions:t,discoverFunctionsGlob:o,configureServer:s,configureApiServer:i,configureGraphQLServer:a,apiPort:n,apiHost:f}=resolveOptions(e),c=path.join(getPaths().base,getConfig().api.serverConfig);fs.existsSync(c)&&console.warn(ansis.yellow(["","Ignoring `config` and `configureServer` in api/server.config.js.","Migrate them to api/src/server.{ts,js}:","",'```js title="api/src/server.{ts,js}"',"// Pass your config to `createServer`","const server = createServer({","  fastifyServerOptions: myFastifyConfig","})","","// Then inline your `configureFastify` logic:","server.register(myFastifyPlugin)","```",""].join("\n")));const p=Object.assign(fastify(t),{start:async()=>{throw new Error("Not implemented yet")}});p.addHook("onRequest",(e,r,t)=>{getAsyncStoreInstance().run(new Map,t)}),s&&await s(p),await p.register(cedarFastifyAPI,{cedar:{apiRootPath:r,fastGlobOptions:{ignore:["**/dist/functions/graphql.js"]},discoverFunctionsGlob:o,configureServer:i}});const[g]=await fg("dist/functions/graphql.{ts,js}",{cwd:getPaths().api.base,absolute:!0});if(g){const{cedarFastifyGraphQLServer:e}=await import("./plugins/graphql.js"),{__cedar_graphqlOptions:t}=await import(pathToFileURL(g).href);await p.register(e,{cedar:{apiRootPath:r,graphql:t,configureServer:a}})}return p.addHook("onReady",e=>{process.send?.("ready"),e()}),p.addHook("onListen",e=>{console.log(`Server listening at ${ansis.magenta(`${p.listeningOrigin}${r}`)}`),e()}),p.start=(e={})=>p.listen({...e,port:n,host:f}),p}process.env.CEDAR_ENV_FILES_LOADED||(config({path:path.join(getPaths().base,".env"),defaults:path.join(getPaths().base,".env.defaults"),multiline:!0}),process.env.CEDAR_ENV_FILES_LOADED="true");export{createServer};
//# sourceMappingURL=/sm/71ae7fd27a785c02ef64ac95192b55f7ad6492eefa9e4f409bed6f93a6f53eda.map