@@ -2,6 +2,7 @@ package main
22
33import (
44 "context"
5+ "flag"
56 "fmt"
67 "log"
78 "os"
@@ -18,11 +19,6 @@ func frontendRouting(server *gin.Engine) {
1819 server .StaticFile ("/vercel.svg" , "./out/vercel.svg" )
1920}
2021
21- // func frontendRouting(server *gin.Engine) {
22- // server.Static("/assets", "./dist/assets")
23- // server.StaticFile("/", "./dist/index.html")
24- // server.StaticFile("/vite.svg", "./dist/vite.svg")
25- // }
2622func GetAllKindsRoute (client * datastore.Client ) gin.HandlerFunc {
2723 return func (c * gin.Context ) {
2824 ctx := context .Background ()
@@ -83,13 +79,38 @@ func CORSMiddleware() gin.HandlerFunc {
8379 }
8480}
8581
86- func main () {
82+ func usage () {
83+ fmt .Fprintf (os .Stderr , "Usage of %s:\n " , os .Args [0 ])
84+ flag .PrintDefaults ()
85+ }
8786
88- port := os . Getenv ( "PORT" )
87+ func main () {
8988
90- if port == "" {
91- log .Fatal ("$PORT must be set" )
89+ files , err := content .ReadDir ("out" )
90+ if err != nil {
91+ fmt .Println ("Error reading embedded directory:" , err )
92+ } else {
93+ fmt .Println ("Files in embedded directory:" )
94+ for _ , file := range files {
95+ fmt .Println (" - " , file .Name ())
96+ }
9297 }
98+ port := flag .String ("port" , "8080" , "Port for the emulator" )
99+ projectId := flag .String ("project" , "my-project" , "Project ID for the emulator" )
100+ emulatorHost := flag .String ("emuHost" , "localhost:8081" , "Host for the emulator" )
101+ emulatorHostPath := flag .String ("emuHostPath" , "localhost:8081/datastore" , "Host path for the emulator" )
102+ datastoreHost := flag .String ("dsHost" , "http://localhost:8081" , "Host for the datastore" )
103+
104+ flag .Usage = usage
105+
106+ flag .Parse ()
107+
108+ os .Setenv ("DATASTORE_DATASET" , * projectId )
109+ os .Setenv ("DATASTORE_EMULATOR_HOST" , * emulatorHost )
110+ os .Setenv ("DATASTORE_EMULATOR_HOST_PATH" , * emulatorHostPath )
111+ os .Setenv ("DATASTORE_HOST" , * datastoreHost )
112+ os .Setenv ("DATASTORE_PROJECT_ID" , * projectId )
113+
93114 fmt .Println ("Starting server on port:" , port )
94115
95116 ctx := context .Background ()
@@ -110,7 +131,7 @@ func main() {
110131 server .GET ("/api/kinds" , GetAllKindsRoute (client ))
111132 server .GET ("/api/entities/:kind/" , GetAllEntitiesRoute (client ))
112133
113- if err := server .Run (":" + port ); err != nil {
134+ if err := server .Run (":" + * port ); err != nil {
114135 log .Fatal ("Error starting server: " , err )
115136 }
116137
0 commit comments