aboutsummaryrefslogtreecommitdiffhomepage
path: root/worker/main.go
blob: ac653054e0b53b21f85d21039fb121ee0f27fc31 (plain)
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
package main

import (
	"log"
	"net/http"
	"os"

	echojwt "github.com/labstack/echo-jwt/v4"
	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
)

func main() {
	jwtSecret := os.Getenv("ALBATROSS_JWT_SECRET")
	if jwtSecret == "" {
		log.Fatal("ALBATROSS_JWT_SECRET is not set")
	}

	if err := prepareDirectories(); err != nil {
		log.Fatal(err)
	}

	e := echo.New()

	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	e.Use(echojwt.WithConfig(echojwt.Config{
		SigningKey: []byte(jwtSecret),
	}))

	e.POST("/api/swiftc", handleSwiftCompile)
	e.POST("/api/wasmc", handleWasmCompile)
	e.POST("/api/testrun", handleTestRun)

	if err := e.Start(":80"); err != http.ErrServerClosed {
		log.Fatal(err)
	}
}