-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
91 lines (72 loc) · 2.29 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
// import (
// "log"
// "net/http"
// "net/http/httputil"
// "net/url"
// )
import (
"fmt"
"log"
"os"
"github.com/RazorSh4rk/lambdaathome/db"
api "github.com/RazorSh4rk/lambdaathome/route-handlers"
setup "github.com/RazorSh4rk/lambdaathome/selfsetup"
"github.com/RazorSh4rk/lambdaathome/ssl"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)
func main() {
setup.Setup()
godotenv.Load()
ginDebug := os.Getenv("GIN_DEBUG")
if ginDebug == "false" || ginDebug == "0" {
fmt.Println("release mode")
gin.SetMode(gin.ReleaseMode)
}
logToFile := os.Getenv("LOG_TO_FILE")
if logToFile == "true" || logToFile == "1" {
logFile, err := os.OpenFile("logfile", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Printf("error opening logfile: %s, logging to std", err)
} else {
log.SetOutput(logFile)
}
defer logFile.Close()
}
router := gin.Default()
router.Use(cors.New(cors.Config{
//AllowOrigins: []string{"*", "*/*"},
AllowAllOrigins: true,
AllowMethods: []string{"*"},
AllowHeaders: []string{"*"},
}))
router.Use(gin.Recovery())
router.Use(api.HandleAuth())
router.OPTIONS("/*any", func(ctx *gin.Context) {
ctx.Header("Access-Control-Allow-Methods", "*") // "GET, POST, DELETE, OPTIONS")
ctx.Header("Access-Control-Allow-Headers", "*") //"Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
ctx.Header("Access-Control-Allow-Origin", "*")
ctx.Header("Content-Type", "application/json")
ctx.JSON(200, gin.H{})
})
runtimeStore := db.New("runtimes-db")
defer runtimeStore.Close()
codeStore := db.New("code-db")
defer codeStore.Close()
api.HandleProxy(router, codeStore)
db.CleanUnusedRuntimes(runtimeStore)
api.HandleNewRuntime(router, runtimeStore)
api.HandleListRuntimes(router, runtimeStore)
api.HandleShowRuntime(router, runtimeStore)
api.HandleDeleteRuntime(router, runtimeStore)
db.RestartServices(codeStore)
api.HandleUploadCode(router, codeStore, runtimeStore)
api.HandleListFunctions(router, codeStore)
api.HandleListRunningFunctions(router, codeStore)
api.HandleKillFunction(router, codeStore)
api.HandleStartBuiltFunction(router, codeStore)
api.HandleListInstalledFunctions(router)
ssl.Run(router)
}