Created
This commit is contained in:
48
server.go
Normal file
48
server.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||
"github.com/gofiber/swagger"
|
||||
|
||||
"gopkg.cloudyne.io/go-fiber-template/config"
|
||||
"gopkg.cloudyne.io/go-fiber-template/helpers"
|
||||
"gopkg.cloudyne.io/go-fiber-template/routers"
|
||||
|
||||
_ "gopkg.cloudyne.io/go-fiber-template/apidocs"
|
||||
)
|
||||
|
||||
// @title Template API
|
||||
// @version 0.1
|
||||
// @description.markdown
|
||||
|
||||
// @contact.name Lars Scheibling
|
||||
// @contact.email it@scheibling.se
|
||||
|
||||
// @license.name AGPLv3
|
||||
|
||||
// @BasePath /
|
||||
func main() {
|
||||
// Check DB Connection
|
||||
config.CheckDB()
|
||||
|
||||
// Create new fiber app
|
||||
app := fiber.New()
|
||||
|
||||
// Set CORS settings
|
||||
app.Use(cors.New(cors.Config{
|
||||
AllowOrigins: config.GetenvDefault("CORS_ALLOW_ORIGINS", "http://localhost:3000,http://127.0.0.1:3000"),
|
||||
AllowMethods: config.GetenvDefault("CORS_ALLOW_METHODS", "GET,POST,HEAD,PUT,DELETE,PATCH,OPTIONS"),
|
||||
AllowCredentials: config.GetenvDefaultLowercase("CORS_ALLOW_CREDENTIALS", "true") == "true",
|
||||
}))
|
||||
|
||||
// Add the route for the swagger documentation
|
||||
app.Get("/docs/*", swagger.HandlerDefault)
|
||||
|
||||
// Add the example router
|
||||
routers.Example(app)
|
||||
|
||||
// Start the app listener, and handle any errors coming from it
|
||||
err := app.Listen(config.GetenvDefault("LISTEN_ADDR", ":3000"))
|
||||
helpers.PanicIfError(err)
|
||||
}
|
||||
Reference in New Issue
Block a user