more frontend work to set backend port

This commit is contained in:
2021-08-25 23:00:18 -04:00
parent 85d6c610f4
commit b9ee7d0790
9 changed files with 1999 additions and 14 deletions

24
main.go
View File

@@ -12,6 +12,7 @@ import (
"github.com/asdine/storm/v3"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/basicauth"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/rs/zerolog"
@@ -39,20 +40,17 @@ func main() {
}
fmt.Println("Server: ", server.Config)
app := fiber.New()
// Setup CORS
app.Use(cors.New(cors.Config{
AllowOrigins: "http://localhost:3000, http://localhost",
AllowHeaders: "Origin, Content-Type, Accept",
}))
// Setup our logger
app.Use(logger.New(logger.Config{
Output: server.LogFile,
TimeZone: server.Config.Timezone,
Format: `{"logtype":"webserver", "pid":"${pid}", "requestid":"${locals:requestid}", "status":"${status}", "method":"${method}", "path":"${path}"}` + "\n",
}))
// Setup our basic authentication if defined
if server.Config.Authentication.BasicAuth {
app.Use(basicauth.New(basicauth.Config{
Users: map[string]string{
server.Config.Authentication.UserName: server.Config.Authentication.Password,
},
}))
}
server.WebServer = app
defer server.LogFile.Close() // Close out our logfile when closing server.
@@ -84,6 +82,16 @@ func main() {
return c.SendString("GoInventorize Backend Hello Route!")
})
// Location Routes
server.WebServer.Get("/config", server.GetServerConfig)
// Setup our basic authentication if defined
if server.Config.Authentication.BasicAuth {
app.Use(basicauth.New(basicauth.Config{
Users: map[string]string{
server.Config.Authentication.UserName: server.Config.Authentication.Password,
},
}))
}
server.WebServer.Get("/locations", server.GetAllLocationsHandler)
server.WebServer.Post("/locations/new", server.AddNewLocationHandler)
server.WebServer.Delete("/locations/:locID", server.DeleteLocationHandler)