chore: init Vue
This commit is contained in:
+9
-4
@@ -10,12 +10,17 @@ import (
|
||||
)
|
||||
|
||||
func KickoffApi(env runtime.Environment, db *gorm.DB) {
|
||||
router := gin.Default()
|
||||
router.LoadHTMLFiles("./web/templates/index.html")
|
||||
r := gin.Default()
|
||||
|
||||
spawnRoutes(router, env, db)
|
||||
api := r.Group("/api")
|
||||
spawnRoutes(api, env, db)
|
||||
|
||||
err := router.Run(fmt.Sprintf("%s:%s", env.Hostname, env.Port))
|
||||
r.Static("/assets", "./web/frontend/dist/assets")
|
||||
r.NoRoute(func(c *gin.Context) {
|
||||
c.File("./web/frontend/dist/index.html")
|
||||
})
|
||||
|
||||
err := r.Run(fmt.Sprintf("%s:%s", env.Hostname, env.Port))
|
||||
if err != nil {
|
||||
slog.Error("failed to start the Gin server due to: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ func categorizeFile(ext string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func spawnRoutes(r *gin.Engine, env runtime.Environment, db *gorm.DB) {
|
||||
func spawnRoutes(api *gin.RouterGroup, env runtime.Environment, db *gorm.DB) {
|
||||
// The Root endpoint '/' displays a simple HTML template.
|
||||
// from root: ./templates/index.html
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
api.GET("/", func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "index.html",
|
||||
gin.H{
|
||||
"title": env.Codename,
|
||||
@@ -41,7 +41,7 @@ func spawnRoutes(r *gin.Engine, env runtime.Environment, db *gorm.DB) {
|
||||
|
||||
// prefix: api
|
||||
// Display the information on what is going on at the moment
|
||||
r.GET("/api/status", func(c *gin.Context) {
|
||||
api.GET("/api/status", func(c *gin.Context) {
|
||||
state, err := database.GetAppState(db)
|
||||
if err != nil {
|
||||
slog.Warn("unable to determine state")
|
||||
@@ -51,7 +51,7 @@ func spawnRoutes(r *gin.Engine, env runtime.Environment, db *gorm.DB) {
|
||||
})
|
||||
|
||||
// define the upload route
|
||||
r.POST("/api/upload", func(c *gin.Context) {
|
||||
api.POST("/api/upload", func(c *gin.Context) {
|
||||
file, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
slog.Error("missing file upload", "error", err)
|
||||
@@ -74,7 +74,7 @@ func spawnRoutes(r *gin.Engine, env runtime.Environment, db *gorm.DB) {
|
||||
})
|
||||
|
||||
// define a route to check what is registered
|
||||
r.GET("/api/available", func(c *gin.Context) {
|
||||
api.GET("/api/available", func(c *gin.Context) {
|
||||
files, err := database.GetFiles(db)
|
||||
if err != nil {
|
||||
slog.Error("failed to retrieve available files", "error", err)
|
||||
|
||||
@@ -38,6 +38,7 @@ func EnsureOperation(workDir string) error {
|
||||
workDir,
|
||||
filepath.Join(workDir, "content"),
|
||||
filepath.Join(workDir, "content", "fresh"),
|
||||
filepath.Join(workDir, "content", "archive"),
|
||||
filepath.Join(workDir, "web"),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user