Setting stuff up for the first proper tests
This commit is contained in:
@@ -2,5 +2,5 @@ package main
|
||||
|
||||
const (
|
||||
blogTitle = "<h2 class='blog-title'>%v</h2>"
|
||||
blogAuthor = "<h4 class='blog-author'>%v</h4>"
|
||||
blogAuthor = "<h4 class='blog-author'><i>%v</i></h4>"
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type PortfolioProject struct {
|
||||
@@ -25,7 +26,7 @@ func (b *BlogApp) Projects(languageFilter string) ([]PortfolioProject, error) {
|
||||
if languageFilter != "" {
|
||||
filter["language.language"] = languageFilter
|
||||
}
|
||||
res, err := b.portfolioCol.Find(context.Background(), filter)
|
||||
res, err := b.portfolioCol.Find(context.Background(), filter, options.Find().SetSort(bson.M{"_id": 1}))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func main() {
|
||||
setupBackend(mux)
|
||||
setupWebsite(mux)
|
||||
serv := &http.Server{
|
||||
Addr: ":443",
|
||||
Addr: ":4223",
|
||||
Handler: mux,
|
||||
}
|
||||
err := serv.ListenAndServeTLS(filepath.Join(flag.Arg(0), "cert.pem"), filepath.Join(flag.Arg(0), "key.pem"))
|
||||
@@ -78,9 +78,15 @@ func setupBackend(mux *http.ServeMux) {
|
||||
if err != nil {
|
||||
log.Fatal("error setting up backend:", err)
|
||||
}
|
||||
mux.Handle("/", back)
|
||||
mux.Handle("api.darkstorm.tech/", back)
|
||||
}
|
||||
|
||||
func setupWebsite(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /files", filesRequest)
|
||||
mux.HandleFunc("GET /portfolio", portfolioRequest)
|
||||
mux.HandleFunc("/", mainHandle)
|
||||
}
|
||||
|
||||
func mainHandle(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
+27
-1
@@ -1,10 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
portfolioSelector = "<p>Language Filter: <select id='langSelect' name='langSelect'>%v</select></p>"
|
||||
portfolioSelectorOption = "<option value='%v'%v>%v</option>"
|
||||
portfolioHeader = "<h2 class='portfolio-header'>%v</h2>"
|
||||
portfolioTitle = "<h2 class='portfolio-title'>%v</h2>"
|
||||
portfolioLink = "<p class='portfolio-link'><a href='%v'>%v</a>"
|
||||
portfolioLanguage = "<p class='portfolio-language'><b>%v</b>: %v</p>"
|
||||
portfolioDesc = "<p class='portfolio-description'>%v</p>"
|
||||
)
|
||||
|
||||
func portfolioRequest(w http.ResponseWriter, r *http.Request) {
|
||||
proj, err := blogApp.Projects(r.URL.Query().Get("lang"))
|
||||
if err != nil {
|
||||
log.Println("error getting portfolio projects:", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
sendIndexWithContent(w, "Error getting portfolio")
|
||||
return
|
||||
}
|
||||
out := ""
|
||||
for _, p := range proj {
|
||||
out += fmt.Sprintf(portfolioTitle, p.Title)
|
||||
out += fmt.Sprintf(portfolioLink, p.Repository, p.Repository)
|
||||
for _, l := range p.Languages {
|
||||
out += fmt.Sprintf(portfolioLanguage, l.Language, l.Dates)
|
||||
}
|
||||
out += fmt.Sprintf(portfolioDesc, p.Description)
|
||||
}
|
||||
sendIndexWithContent(w, out)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user