Skip to content

Commit

Permalink
update: segment api routes and add frontend routes
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijit-hota committed May 16, 2022
1 parent 176b66f commit 1eabde4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
32 changes: 29 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,45 @@ import (
"api/db"
"api/handlers"
"api/utils"
"net/http"

"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
)

func CORSMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")

if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(204)
return
}

c.Next()
}
}

func main() {
godotenv.Load()
utils.LoadConfig()
db.InitializeDB()

router := gin.Default()
router.Use(CORSMiddleware())
router.Static("css", "views/css")
router.Static("js", "views/js")
router.LoadHTMLGlob("views/html/*.html")

router.GET("/", func(ctx *gin.Context) {
ctx.HTML(http.StatusOK, "index.html", nil)
})

bookmarkRouter := router.Group("/bookmarks")
apiRouter := router.Group("/api")
bookmarkRouter := apiRouter.Group("/bookmarks")
{
bookmarkRouter.POST("", handlers.AddBookmark)
bookmarkRouter.GET("", handlers.GetBookmarks)
Expand All @@ -27,7 +53,7 @@ func main() {
bookmarkRouter.DELETE("/:id", handlers.DeleteBookmark)
bookmarkRouter.DELETE("", handlers.BulkDeleteBookmarks)
}
tagRouter := router.Group("/tags")
tagRouter := apiRouter.Group("/tags")
{
tagRouter.POST("", handlers.CreateTag)
tagRouter.GET("", handlers.GetAllTags)
Expand All @@ -36,7 +62,7 @@ func main() {
tagRouter.GET("/tree", handlers.GetLinkTree)
}

configRouter := router.Group("/config")
configRouter := apiRouter.Group("/config")
{
configRouter.GET("", handlers.GetConfig)
configRouter.PATCH("/save-offline", handlers.ToggleSaveOffline)
Expand Down
16 changes: 10 additions & 6 deletions api/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@
- [ ] Pagination
- [x] meta favicon bug
12
- [ ] Search
- [x] Search
- https://www.sqlite.org/fts5.html
- [ ] Import/Export
- [ ] Save as PDF/HTML
- go-shiori/Orca
- go-shiori/readability
- [x] Save offline as HTML
13
- [ ] Browser extension
- [ ] Web frontend
Expand All @@ -57,7 +55,13 @@
- [?] Sync
- [ ] Phone frontend


- [-] Desktop frontend
- [-] CLI frontend



### Finishing

- [ ] Standardize Logging
- [ ] Standardize errors
- [ ] Publishing
- [ ] Trimming binaries

0 comments on commit 1eabde4

Please sign in to comment.