2023-04-29 17:38:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-06-29 09:48:56 +00:00
|
|
|
"context"
|
2023-04-29 17:38:21 +00:00
|
|
|
"embed"
|
|
|
|
"git.lumeweb.com/LumeWeb/portal/config"
|
2023-05-10 11:07:56 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/controller"
|
2023-04-29 17:38:21 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/db"
|
2023-04-30 06:18:42 +00:00
|
|
|
_ "git.lumeweb.com/LumeWeb/portal/docs"
|
2023-05-22 23:05:38 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/logger"
|
2023-06-29 09:48:56 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/middleware"
|
2023-06-09 08:03:29 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/service/auth"
|
2023-05-10 18:28:32 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/service/files"
|
2023-06-29 09:48:56 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/shared"
|
2023-05-16 22:45:32 +00:00
|
|
|
"git.lumeweb.com/LumeWeb/portal/tus"
|
2023-04-30 06:18:42 +00:00
|
|
|
"github.com/iris-contrib/swagger"
|
|
|
|
"github.com/iris-contrib/swagger/swaggerFiles"
|
2023-04-29 17:38:21 +00:00
|
|
|
"github.com/kataras/iris/v12"
|
2023-06-29 09:48:56 +00:00
|
|
|
irisContext "github.com/kataras/iris/v12/context"
|
2023-06-28 05:06:38 +00:00
|
|
|
"github.com/kataras/iris/v12/middleware/cors"
|
2023-04-29 17:38:21 +00:00
|
|
|
"github.com/kataras/iris/v12/mvc"
|
2023-05-19 13:04:47 +00:00
|
|
|
"go.uber.org/zap"
|
2023-04-29 17:38:21 +00:00
|
|
|
"log"
|
2023-05-10 18:28:32 +00:00
|
|
|
"net/http"
|
2023-04-29 17:38:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Embed a directory of static files for serving from the app's root path
|
2023-05-04 08:21:39 +00:00
|
|
|
//
|
2023-04-29 17:38:21 +00:00
|
|
|
//go:embed app/*
|
|
|
|
var embedFrontend embed.FS
|
|
|
|
|
2023-04-30 06:46:47 +00:00
|
|
|
// @title Lume Web Portal
|
|
|
|
// @version 1.0
|
|
|
|
// @description A decentralized data storage portal for the open web
|
2023-04-30 06:18:42 +00:00
|
|
|
|
2023-04-30 06:46:47 +00:00
|
|
|
// @contact.name Lume Web Project
|
|
|
|
// @contact.url https://lumeweb.com
|
|
|
|
// @contact.email contact@lumeweb.com
|
2023-04-30 06:18:42 +00:00
|
|
|
|
2023-04-30 06:46:47 +00:00
|
|
|
// @license.name MIT
|
|
|
|
// @license.url https://opensource.org/license/mit/
|
2023-04-30 06:18:42 +00:00
|
|
|
|
2023-05-04 08:20:39 +00:00
|
|
|
// @externalDocs.description OpenAPI
|
|
|
|
// @externalDocs.url https://swagger.io/resources/open-api/
|
2023-04-29 17:38:21 +00:00
|
|
|
func main() {
|
|
|
|
// Initialize the configuration settings
|
|
|
|
config.Init()
|
|
|
|
|
2023-04-30 06:10:52 +00:00
|
|
|
// Initialize the database connection
|
|
|
|
db.Init()
|
2023-05-22 23:05:38 +00:00
|
|
|
logger.Init()
|
2023-05-10 18:28:32 +00:00
|
|
|
files.Init()
|
2023-06-09 08:03:29 +00:00
|
|
|
auth.Init()
|
2023-05-04 08:21:39 +00:00
|
|
|
|
2023-04-29 17:38:21 +00:00
|
|
|
// Create a new Iris app instance
|
|
|
|
app := iris.New()
|
|
|
|
// Enable Gzip compression for responses
|
|
|
|
app.Use(iris.Compression)
|
2023-06-28 05:06:38 +00:00
|
|
|
app.UseRouter(cors.New().Handler())
|
2023-04-29 17:38:21 +00:00
|
|
|
|
|
|
|
// Serve static files from the embedded directory at the app's root path
|
|
|
|
app.HandleDir("/", embedFrontend)
|
|
|
|
|
2023-04-30 07:30:03 +00:00
|
|
|
api := app.Party("/api")
|
|
|
|
v1 := api.Party("/v1")
|
|
|
|
|
2023-06-29 09:48:56 +00:00
|
|
|
tusHandler := tus.Init()
|
|
|
|
|
2023-05-10 11:07:56 +00:00
|
|
|
// Register the AccountController with the MVC framework and attach it to the "/api/account" path
|
2023-04-30 07:30:03 +00:00
|
|
|
mvc.Configure(v1.Party("/account"), func(app *mvc.Application) {
|
2023-05-10 18:23:22 +00:00
|
|
|
app.Handle(new(controller.AccountController))
|
2023-04-29 17:38:21 +00:00
|
|
|
})
|
|
|
|
|
2023-04-30 07:30:03 +00:00
|
|
|
mvc.Configure(v1.Party("/auth"), func(app *mvc.Application) {
|
2023-05-10 18:23:22 +00:00
|
|
|
app.Handle(new(controller.AuthController))
|
2023-04-29 17:38:21 +00:00
|
|
|
})
|
|
|
|
|
2023-05-04 08:21:39 +00:00
|
|
|
mvc.Configure(v1.Party("/files"), func(app *mvc.Application) {
|
2023-06-29 09:48:56 +00:00
|
|
|
tusRoute := app.Router.Party(tus.TUS_API_PATH)
|
|
|
|
tusRoute.Use(middleware.VerifyJwt)
|
|
|
|
|
|
|
|
fromStd := func(handler http.Handler) func(ctx *irisContext.Context) {
|
|
|
|
return func(ctx *irisContext.Context) {
|
|
|
|
newCtx := context.WithValue(ctx.Request().Context(), shared.TusRequestContextKey, ctx)
|
|
|
|
handler.ServeHTTP(ctx.ResponseWriter(), ctx.Request().WithContext(newCtx))
|
|
|
|
}
|
|
|
|
}
|
2023-05-04 08:21:39 +00:00
|
|
|
|
2023-06-29 09:48:56 +00:00
|
|
|
tusRoute.Any("/{fileparam:path}", fromStd(http.StripPrefix(v1.GetRelPath()+tus.TUS_API_PATH+"/", tusHandler)))
|
|
|
|
tusRoute.Post("/", fromStd(http.StripPrefix(tusRoute.GetRelPath()+tus.TUS_API_PATH, tusHandler)))
|
2023-05-10 18:28:32 +00:00
|
|
|
|
2023-06-29 09:48:56 +00:00
|
|
|
app.Handle(new(controller.FilesController))
|
|
|
|
})
|
2023-05-10 18:28:32 +00:00
|
|
|
|
2023-04-30 07:30:19 +00:00
|
|
|
swaggerConfig := swagger.Config{
|
2023-04-30 06:18:42 +00:00
|
|
|
// The url pointing to API definition.
|
|
|
|
URL: "http://localhost:8080/swagger/doc.json",
|
|
|
|
DeepLinking: true,
|
|
|
|
DocExpansion: "list",
|
|
|
|
DomID: "#swagger-ui",
|
|
|
|
// The UI prefix URL (see route).
|
|
|
|
Prefix: "/swagger",
|
|
|
|
}
|
2023-04-30 07:30:19 +00:00
|
|
|
swaggerUI := swagger.Handler(swaggerFiles.Handler, swaggerConfig)
|
2023-04-30 06:18:42 +00:00
|
|
|
|
|
|
|
app.Get("/swagger", swaggerUI)
|
|
|
|
// And the wildcard one for index.html, *.js, *.css and e.t.c.
|
|
|
|
app.Get("/swagger/{any:path}", swaggerUI)
|
|
|
|
|
2023-04-29 17:38:21 +00:00
|
|
|
// Start the Iris app and listen for incoming requests on port 80
|
2023-05-08 14:09:33 +00:00
|
|
|
err := app.Listen(":8080", func(app *iris.Application) {
|
2023-04-30 07:30:19 +00:00
|
|
|
routes := app.GetRoutes()
|
|
|
|
for _, route := range routes {
|
|
|
|
log.Println(route)
|
|
|
|
}
|
2023-05-08 14:09:33 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
2023-05-22 23:05:38 +00:00
|
|
|
logger.Get().Error("Failed starting webserver proof", zap.Error(err))
|
2023-05-08 14:09:33 +00:00
|
|
|
}
|
2023-04-29 17:38:21 +00:00
|
|
|
}
|