MCPcopy
hub / github.com/redwoodjs/graphql / createServer

Function createServer

packages/api-server/src/createServer.ts:66–181  ·  view source on GitHub ↗
(options: CreateServerOptions = {})

Source from the content-addressed store, hash-verified

64 * ```
65 */
66export async function createServer(options: CreateServerOptions = {}) {
67 const {
68 apiRootPath,
69 fastifyServerOptions,
70 discoverFunctionsGlob,
71 configureApiServer,
72 apiPort,
73 apiHost,
74 } = resolveOptions(options)
75
76 // Warn about `api/server.config.js`
77 const serverConfigPath = path.join(
78 getPaths().base,
79 getConfig().api.serverConfig,
80 )
81
82 if (fs.existsSync(serverConfigPath)) {
83 console.warn(
84 chalk.yellow(
85 [
86 '',
87 `Ignoring \`config\` and \`configureServer\` in api/server.config.js.`,
88 `Migrate them to api/src/server.{ts,js}:`,
89 '',
90 `\`\`\`js title="api/src/server.{ts,js}"`,
91 '// Pass your config to `createServer`',
92 'const server = createServer({',
93 ' fastifyServerOptions: myFastifyConfig',
94 '})',
95 '',
96 '// Then inline your `configureFastify` logic:',
97 'server.register(myFastifyPlugin)',
98 '```',
99 '',
100 ].join('\n'),
101 ),
102 )
103 }
104
105 // Initialize the fastify instance
106 const server: Server = Object.assign(fastify(fastifyServerOptions), {
107 // `start` will get replaced further down in this file
108 start: async () => {
109 throw new Error('Not implemented yet')
110 },
111 })
112
113 server.addHook('onRequest', (_req, _reply, done) => {
114 getAsyncStoreInstance().run(new Map<string, GlobalContext>(), done)
115 })
116
117 await server.register(redwoodFastifyAPI, {
118 redwood: {
119 apiRootPath,
120 fastGlobOptions: {
121 ignore: ['**/dist/functions/graphql.js'],
122 },
123 discoverFunctionsGlob,

Callers 2

handlerFunction · 0.90

Calls 8

resolveOptionsFunction · 0.90
getPathsFunction · 0.90
getConfigFunction · 0.90
getAsyncStoreInstanceFunction · 0.90
registerMethod · 0.80
existsSyncMethod · 0.65
runMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected