Newer
Older

Guilhem CARRON
committed
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
package main
import (
"fmt"
"net/http"
"strconv"
"log"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/common"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/mocks"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/rootmux"
"forge.grandlyon.com/web-et-numerique/llle_project/backoffice-server/internal/tokens"
)
var (
httpsPort = common.IntValueFromEnv("HTTPS_PORT", 443) // HTTPS port to serve on
debugMode = common.BoolValueFromEnv("DEBUG_MODE", false) // Debug mode, disable Secure attribute for cookies
mockOAuth2 = common.BoolValueFromEnv("MOCK_OAUTH2", false) // Enable mock OAuth2 login
)
func main() {
log.Println("--- Server is starting ---")
// Initializations
tokens.Init("./configs/tokenskey.json", debugMode)
// Create the server
rootMux := rootmux.CreateRootMux()
// Init the hostname
mocks.Init(httpsPort)
// Start a mock oauth2 server if debug mode is on
if mockOAuth2 {
mockOAuth2Port := ":8090"
go http.ListenAndServe(mockOAuth2Port, mocks.CreateMockOAuth2())
fmt.Println("Mock OAuth2 server Listening on: http://localhost" + mockOAuth2Port)
}
// Serve locally with https
log.Fatal(http.ListenAndServeTLS(":"+strconv.Itoa(httpsPort), "./dev_certificates/localhost.crt", "./dev_certificates/localhost.key", rootMux.Router))
// log.Fatal(http.ListenAndServe(":"+strconv.Itoa(httpsPort), rootMux.Router))