-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (61 loc) · 1.49 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"net/http"
"os"
"strings"
"github.com/dibrinsofor/mlsa3/handlers"
"github.com/fsnotify/fsnotify"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func SetupServer() *gin.Engine {
r := gin.Default()
corsConfig := cors.DefaultConfig()
corsConfig.AllowAllOrigins = true
corsConfig.AllowCredentials = true
r.Use(cors.New(corsConfig))
r.GET("/health", handlers.HealthCheck())
r.POST("/createUser", handlers.CreateUser)
// r.GET("/", handlers.VerifyUser)
r.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Message Queues Demo",
"subheading": "Create Account",
})
})
return r
}
func main() {
r := SetupServer()
r.LoadHTMLGlob("templates/*")
watcher, err := fsnotify.NewWatcher()
if err != nil {
fmt.Println("ERROR", err)
}
defer watcher.Close()
// watch for App_offline.htm and exit the program if present
// This allows continuous deployment on App Service as the .exe will not be
// terminated otherwise
go func() {
for {
select {
case event := <-watcher.Events:
if strings.HasSuffix(event.Name, "app_offline.htm") {
fmt.Println("Exiting due to app_offline.htm being present")
os.Exit(0)
}
}
}
}()
// get the current working directory and watch it
currentDir, err := os.Getwd()
if err := watcher.Add(currentDir); err != nil {
fmt.Println("ERROR", err)
}
port := os.Getenv("HTTP_PLATFORM_PORT")
if port == "" {
port = "6969"
}
r.Run("127.0.0.1:" + port)
}