/
main.go
61 lines (48 loc) · 1.31 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
package main
import (
"context"
"log"
"os"
"os/signal"
"time"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
// init
app := echo.New()
// handle recovers from panics anywhere
app.Use(middleware.Recover())
// handle CORS
app.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"https://multissh.github.io"},
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
}))
// static route
app.Static("/.well-known", "./.well-known")
// live ssh route
app.GET("/", listTermHandler)
app.POST("/term", createTermHandler)
app.POST("/term/:id/windowsize", setTermWindowSizeHandler)
app.GET("/term/:id/data", linkTermDataHandler)
// snippet ssh route
app.GET("/run", runCmd)
// config route
app.GET("/server", getConfig)
app.GET("/snippets", getConfig)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
// start http server
go func() {
log.Fatal(app.Start(":80"))
}()
// start https server
go func() {
log.Fatal(app.StartTLS(":443", "./cert.crt", "./private.key"))
}()
// signal to gracefully shutdown the server with a timeout of 10 seconds
<-ctx.Done()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
app.Shutdown(ctx)
}