-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (47 loc) · 1.81 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
package main
import (
"github.com/asphaltbot/file-storage/routes"
"github.com/asphaltbot/file-storage/util"
"github.com/getsentry/raven-go"
"github.com/gin-contrib/cors"
"github.com/gin-contrib/gzip"
"github.com/gin-contrib/sentry"
"github.com/gin-gonic/autotls"
"github.com/gin-gonic/gin"
"golang.org/x/crypto/acme/autocert"
"log"
"time"
)
func main() {
r := gin.Default()
r.Use(sentry.Recovery(raven.DefaultClient, false))
r.Use(gzip.Gzip(gzip.DefaultCompression))
r.Use(cors.New(cors.Config{
AllowAllOrigins: true,
AllowMethods: []string{"GET", "POST", "DELETE"},
AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 24 * time.Hour,
}))
registerRoutes(r)
r.GET("/", Index)
if util.IsRunningInProd() {
gin.SetMode(gin.ReleaseMode)
m := autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist("storage.asphaltbot.com"),
Cache: autocert.DirCache("/home/storage/cache"),
}
log.Fatal(autotls.RunWithManager(r, &m))
} else {
gin.SetMode(gin.DebugMode)
_ = r.Run(":80")
}
}
func Index(c *gin.Context) {
c.Data(200, "text/html", []byte("<!DOCTYPE html><html lang=\"en\" dir=\"ltr\"> <head> <meta charset=\"utf-8\"> <title>Asphalt Storage Server</title> <link href=\"https://fonts.googleapis.com/css?family=Roboto&display=swap\" rel=\"stylesheet\"> <style>h1, p, small{font-family: 'Roboto', sans-serif;}</style> </head> <body> <div align=\"center\"> <h1>Asphalt Storage Server</h1> <p>This server is running custom open source storage software, click <a href=\"https://github.com/asphaltbot/file-storage\">here</a> for more information.</p><br/> <small>Created by Connor Wright</small> </div></body></html>"))
}
func registerRoutes(e *gin.Engine) {
routes.RegisterUploadRoutes(e)
}