-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
66 lines (49 loc) · 1.55 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
package main
import (
"log"
"net/http"
"os"
"strings"
"github.com/usual2970/meta-forge/internal/routes"
"github.com/usual2970/meta-forge/internal/util/app"
"github.com/usual2970/meta-forge/ui"
"github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/middleware"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/plugins/migratecmd"
_ "github.com/pocketbase/pocketbase/migrations"
_ "github.com/usual2970/meta-forge/migrations"
)
const mfPath = "/mf/"
func main() {
os.Setenv("SERPAPI_API_KEY", "0cc261b4c1814a7f2d9ed79df97df998a0232c3059df1733532cce6610f04c42")
app := app.Get()
isGoRun := strings.HasPrefix(os.Args[0], os.TempDir())
migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{
// enable auto creation of migration files when making collection changes in the Admin UI
// (the isGoRun check is to enable it only during development)
Automigrate: isGoRun,
})
app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
e.Router.GET(
strings.TrimRight(mfPath, "/"),
func(c echo.Context) error {
return c.Redirect(http.StatusTemporaryRedirect, strings.TrimLeft(mfPath, "/"))
},
)
e.Router.GET(
mfPath+"*",
echo.StaticDirectoryHandler(ui.DistDirFS, false),
middleware.Gzip(),
)
e.Router.GET("/hello/:name", func(c echo.Context) error {
name := c.PathParam("name")
return c.JSON(http.StatusOK, map[string]string{"message": "Hello " + name})
} /* optional middlewares */)
routes.Route(e.Router)
return nil
})
if err := app.Start(); err != nil {
log.Fatal(err)
}
}