@@ -4,24 +4,13 @@ import path from 'node:path'
4
4
import chalk from 'chalk'
5
5
import { config } from 'dotenv-defaults'
6
6
import execa from 'execa'
7
- import Fastify from 'fastify'
8
7
import open from 'open'
9
8
import { SMTPServer } from 'smtp-server'
10
9
11
- import {
12
- coerceRootPath ,
13
- redwoodFastifyWeb ,
14
- redwoodFastifyAPI ,
15
- redwoodFastifyGraphQLServer ,
16
- DEFAULT_REDWOOD_FASTIFY_CONFIG ,
17
- } from '@redwoodjs/fastify'
18
-
19
- import directives from 'src/directives/**/*.{js,ts}'
20
- import sdls from 'src/graphql/**/*.sdl.{js,ts}'
21
- import services from 'src/services/**/*.{js,ts}'
10
+ import { createServer } from '@redwoodjs/api-server'
11
+ import { coerceRootPath , redwoodFastifyWeb } from '@redwoodjs/fastify'
22
12
23
13
import { logger } from 'src/lib/logger'
24
- import { realtime } from 'src/lib/realtime'
25
14
26
15
import { startConnectionWatching } from './util/connectionWatching'
27
16
import { startWatchers } from './util/fsWatching'
@@ -93,32 +82,15 @@ export async function serve(
93
82
94
83
rewriteApiPortEnvVar ( apiPort )
95
84
96
- const fastify = Fastify ( DEFAULT_REDWOOD_FASTIFY_CONFIG )
85
+ const server = await createServer ( {
86
+ apiRootPath,
87
+ } )
97
88
98
89
if ( enableWeb ) {
99
- await fastify . register ( redwoodFastifyWeb )
90
+ await server . register ( redwoodFastifyWeb )
100
91
}
101
92
102
- await fastify . register ( redwoodFastifyAPI , {
103
- redwood : {
104
- apiRootPath,
105
- } ,
106
- } )
107
-
108
- await fastify . register ( redwoodFastifyGraphQLServer , {
109
- loggerConfig : {
110
- logger : logger ,
111
- } ,
112
- graphiQLEndpoint : enableWeb ? '/.redwood/functions/graphql' : '/graphql' ,
113
- sdls,
114
- services,
115
- directives,
116
- allowIntrospection : true ,
117
- allowGraphiQL : true ,
118
- realtime,
119
- } )
120
-
121
- await fastify . register ( graphqlProxy )
93
+ await server . register ( graphqlProxy )
122
94
123
95
// Start filesystem watchers
124
96
await startWatchers ( )
@@ -138,8 +110,8 @@ export async function serve(
138
110
} )
139
111
140
112
// Start
141
- fastify . listen ( { port : apiPort } )
142
- fastify . ready ( ( ) => {
113
+ server . listen ( { port : apiPort } )
114
+ server . ready ( ( ) => {
143
115
logger . info ( 'Studio is up and running!' )
144
116
logger . info (
145
117
`To access the Studio, visit ${ chalk . green (
@@ -154,7 +126,7 @@ export async function serve(
154
126
155
127
// Cleanup (async will not be resolved!)
156
128
process . on ( 'exit' , ( ) => {
157
- fastify . close ( )
129
+ server . close ( )
158
130
} )
159
131
}
160
132
0 commit comments