move webserver files to ./web/
This commit is contained in:
41
src/web/app/app.go
Normal file
41
src/web/app/app.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"crowsnest/internal/model/database"
|
||||
"database/sql"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
articles *database.ArticleRepository
|
||||
articleVMs *database.ArticleViewModelRepository
|
||||
articlePageVMs *database.ArticlePageViewModelRepository
|
||||
rssItems *database.RSSItemRepository
|
||||
}
|
||||
|
||||
func NewApp(db *sql.DB) *App {
|
||||
return &App{
|
||||
articles: &database.ArticleRepository{DB: db},
|
||||
articleVMs: &database.ArticleViewModelRepository{DB: db},
|
||||
articlePageVMs: &database.ArticlePageViewModelRepository{DB: db},
|
||||
rssItems: &database.RSSItemRepository{DB: db},
|
||||
}
|
||||
}
|
||||
|
||||
func (app *App) Routes() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// dynamic routes
|
||||
mux.Handle("GET /rss.xml", http.HandlerFunc(app.RSS))
|
||||
|
||||
mux.Handle("GET /", http.HandlerFunc(app.Index))
|
||||
mux.Handle("GET /page/{id}", http.HandlerFunc(app.Index))
|
||||
mux.Handle("POST /up/search", http.HandlerFunc(app.UpSearch))
|
||||
|
||||
mux.Handle("GET /article/{id}", http.HandlerFunc(app.Article))
|
||||
|
||||
// serve files from the "static" directory
|
||||
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./assets/static"))))
|
||||
|
||||
return mux
|
||||
}
|
||||
Reference in New Issue
Block a user