-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
62 lines (50 loc) · 1.27 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
package main
import (
"fmt"
"gopkg.in/fsnotify.v1"
"os"
"strings"
"github.com/rizkyrsyd28/internal/route"
"github.com/gin-gonic/gin"
"github.com/gin-contrib/cors"
)
func main() {
r := gin.Default()
// Add CORS middleware
config := cors.DefaultConfig()
config.AllowOrigins = []string{"http://localhost:3000", "https://saddamannais.github.io"}
config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE"}
r.Use(cors.New(config))
route.Routes(r)
// creates a new file watcher for App_offline.htm
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 = "8080"
}
// Start the server
r.Run(":" + port)
}