/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@cedarjs/api-server@4.0.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"path";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:t,fastifyServerOptions:r,discoverFunctionsGlob:s,configureApiServer:o,apiPort:i,apiHost:a}=resolveOptions(e),n=path.join(getPaths().base,getConfig().api.serverConfig);fs.existsSync(n)&&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 f=Object.assign(fastify(r),{start:async()=>{throw new Error("Not implemented yet")}});f.addHook("onRequest",((e,t,r)=>{getAsyncStoreInstance().run(new Map,r)})),await f.register(cedarFastifyAPI,{redwood:{apiRootPath:t,fastGlobOptions:{ignore:["**/dist/functions/graphql.js"]},discoverFunctionsGlob:s,configureServer:o}});const[p]=await fg("dist/functions/graphql.{ts,js}",{cwd:getPaths().api.base,absolute:!0});if(p){const{redwoodFastifyGraphQLServer:e}=await import("./plugins/graphql.js"),{__rw_graphqlOptions:r}=await import(`file://${p}`);await f.register(e,{redwood:{apiRootPath:t,graphql:r}})}return f.addHook("onReady",(e=>{process.send?.("ready"),e()})),f.addHook("onListen",(e=>{console.log(`Server listening at ${ansis.magenta(`${f.listeningOrigin}${t}`)}`),e()})),f.start=(e={})=>f.listen({...e,port:i,host:a}),f}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/2eb8c585d636386e046dd06ad06c5f994859f5f24d71b096b78d5862a69a94f9.map