-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
44 lines (34 loc) · 1.19 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"github.com/buaazp/fasthttprouter"
catalogtSerivces "github.com/j-ew-s/ms-curso-catalog-api/catalog-services"
database "github.com/j-ew-s/ms-curso-catalog-api/database"
"github.com/valyala/fasthttp"
)
func main() {
router := fasthttprouter.New()
dbConn := SetDataBase()
catService := catalogtSerivces.CatalogServiceMain(&dbConn)
catalogtSerivces.SetRoutes(router, catService)
fasthttp.ListenAndServe(":5200", CORS(router.Handler))
}
var (
corsAllowHeaders = "*"
corsAllowMethods = "HEAD,GET,POST,PUT,DELETE,OPTIONS"
corsAllowOrigin = "*"
corsAllowCredentials = "true"
)
// CORS handles CORS
func CORS(next fasthttp.RequestHandler) fasthttp.RequestHandler {
return func(ctx *fasthttp.RequestCtx) {
ctx.Response.Header.Set("Access-Control-Allow-Credentials", corsAllowCredentials)
ctx.Response.Header.Set("Access-Control-Allow-Headers", corsAllowHeaders)
ctx.Response.Header.Set("Access-Control-Allow-Methods", corsAllowMethods)
ctx.Response.Header.Set("Access-Control-Allow-Origin", corsAllowOrigin)
next(ctx)
}
}
func SetDataBase() database.MongoDBConfig {
conn := database.SetupMongoDBConfig("127.0.0.1", 27017, "mongoadmin", "secret")
return conn
}