@@ -40,7 +40,11 @@ func ParseEnvFile(envFilePath string) ([]string, error) {
40
40
return env , nil
41
41
}
42
42
43
- func Run (ctx context.Context , slug string , envFilePath string , noVerifyJWT * bool , importMapPath string , fsys afero.Fs ) error {
43
+ func Run (ctx context.Context , slug string , envFilePath string , noVerifyJWT * bool , importMapPath string , serveAll bool , fsys afero.Fs ) error {
44
+ if serveAll {
45
+ return runServeAll (ctx , envFilePath , noVerifyJWT , importMapPath , fsys )
46
+ }
47
+
44
48
// 1. Sanity checks.
45
49
{
46
50
if err := utils .LoadConfigFS (fsys ); err != nil {
@@ -216,3 +220,89 @@ func Run(ctx context.Context, slug string, envFilePath string, noVerifyJWT *bool
216
220
fmt .Println ("Stopped serving " + utils .Bold (localFuncDir ))
217
221
return nil
218
222
}
223
+
224
+ func runServeAll (ctx context.Context , envFilePath string , noVerifyJWT * bool , importMapPath string , fsys afero.Fs ) error {
225
+ // 1. Sanity checks.
226
+ {
227
+ if err := utils .LoadConfigFS (fsys ); err != nil {
228
+ return err
229
+ }
230
+ if err := utils .AssertSupabaseDbIsRunning (); err != nil {
231
+ return err
232
+ }
233
+ if envFilePath != "" {
234
+ if _ , err := fsys .Stat (envFilePath ); err != nil {
235
+ return fmt .Errorf ("Failed to read env file: %w" , err )
236
+ }
237
+ }
238
+ if importMapPath != "" {
239
+ // skip
240
+ } else if f , err := fsys .Stat (utils .FallbackImportMapPath ); err == nil && ! f .IsDir () {
241
+ importMapPath = utils .FallbackImportMapPath
242
+ }
243
+ if importMapPath != "" {
244
+ if _ , err := fsys .Stat (importMapPath ); err != nil {
245
+ return fmt .Errorf ("Failed to read import map: %w" , err )
246
+ }
247
+ }
248
+ }
249
+
250
+ // 2. Parse user defined env
251
+ userEnv , err := ParseEnvFile (envFilePath )
252
+ if err != nil {
253
+ return err
254
+ }
255
+
256
+ // 3. Start container
257
+ {
258
+ _ = utils .Docker .ContainerRemove (ctx , utils .DenoRelayId , types.ContainerRemoveOptions {
259
+ RemoveVolumes : true ,
260
+ Force : true ,
261
+ })
262
+
263
+ env := []string {
264
+ "JWT_SECRET=" + utils .JWTSecret ,
265
+ "SUPABASE_URL=http://" + utils .KongId + ":8000" ,
266
+ "SUPABASE_ANON_KEY=" + utils .AnonKey ,
267
+ "SUPABASE_SERVICE_ROLE_KEY=" + utils .ServiceRoleKey ,
268
+ "SUPABASE_DB_URL=postgresql://postgres:postgres@localhost:" + strconv .FormatUint (uint64 (utils .Config .Db .Port ), 10 ) + "/postgres" ,
269
+ }
270
+ verifyJWTEnv := "VERIFY_JWT=true"
271
+ if noVerifyJWT != nil {
272
+ verifyJWTEnv = "VERIFY_JWT=false"
273
+ }
274
+ env = append (env , verifyJWTEnv )
275
+
276
+ cwd , err := os .Getwd ()
277
+ if err != nil {
278
+ return err
279
+ }
280
+
281
+ binds := []string {
282
+ filepath .Join (cwd , utils .FunctionsDir ) + ":" + relayFuncDir + ":ro,z" ,
283
+ utils .DenoRelayId + ":/root/.cache/deno:rw,z" ,
284
+ }
285
+ // If a import map path is explcitly provided, mount it as a separate file
286
+ if importMapPath != "" {
287
+ binds = append (binds , filepath .Join (cwd , importMapPath )+ ":" + customDockerImportMapPath + ":ro,z" )
288
+ }
289
+
290
+ fmt .Println ("Serving " + utils .Bold (utils .FunctionsDir ))
291
+
292
+ if err := utils .DockerRunOnceWithStream (
293
+ ctx ,
294
+ utils .EdgeRuntimeImage ,
295
+ append (env , userEnv ... ),
296
+ []string {"start" , "--dir" , relayFuncDir , "-p" , "8081" },
297
+ binds ,
298
+ os .Stdout ,
299
+ os .Stderr ,
300
+ ); err != nil {
301
+ return err
302
+ }
303
+ }
304
+
305
+ fmt .Println ("Stopped serving " + utils .Bold (utils .FunctionsDir ))
306
+ return nil
307
+
308
+ }
0 commit comments