Compare commits

..

11 Commits

Author SHA1 Message Date
Max Richter
137e3da6d4 fix: some stuff
All checks were successful
Build and Push Server / build-and-push (push) Successful in 3m12s
2025-11-04 12:42:15 +01:00
Max Richter
148bc2c15c fix: some stuff
Some checks failed
Build and Push Server / build-and-push (push) Failing after 2m55s
2025-11-04 12:38:24 +01:00
Max Richter
cc19724277 chore: update
Some checks failed
Build and Push Server / build-and-push (push) Failing after 4m8s
2025-11-04 12:26:38 +01:00
Max Richter
851babe1e0 fix: dont writeJSON twice
All checks were successful
Build and Push Server / build-and-push (push) Successful in 2m51s
2025-10-31 20:08:33 +01:00
Max Richter
f14b685e43 fix: make sure we dont try to decode jpgs into json
All checks were successful
Build and Push Server / build-and-push (push) Successful in 3m17s
2025-10-31 19:39:44 +01:00
Max Richter
fd6aeb8a27 feat: add some more detailed errors
All checks were successful
Build and Push Server / build-and-push (push) Successful in 2m54s
2025-10-31 19:32:36 +01:00
Max Richter
4bfd2b9450 fix: return content of written article
All checks were successful
Build and Push Server / build-and-push (push) Successful in 2m51s
2025-10-31 19:18:45 +01:00
Max Richter
dfc38e2c86 fix: make templates work
All checks were successful
Build and Push Server / build-and-push (push) Successful in 2m57s
2025-10-31 18:16:33 +01:00
Max Richter
3fe7577250 fix: return json from write post
All checks were successful
Build and Push Server / build-and-push (push) Successful in 2m53s
2025-10-31 17:27:15 +01:00
Max Richter
3cd320637c fix: return status ok for write
All checks were successful
Build and Push Server / build-and-push (push) Successful in 6m31s
2025-10-31 15:24:48 +01:00
Max Richter
7c5f9f7829 feat: add some log
All checks were successful
Build and Push Server / build-and-push (push) Successful in 13m1s
2025-10-31 14:41:46 +01:00
6 changed files with 20 additions and 8 deletions

View File

@@ -38,5 +38,4 @@
--- ---
# { headline } # { headline }
{ articleBody } { articleBody }

View File

@@ -36,7 +36,6 @@
--- ---
# { name | text } # { name | text }
{ description | text } { description | text }
## Ingredients ## Ingredients

View File

@@ -37,5 +37,4 @@
--- ---
# { itemReviewed.name } # { itemReviewed.name }
{ reviewBody } { reviewBody }

View File

@@ -9,7 +9,7 @@ cmd = "go build -o ./tmp/marka-server ./cmd/marka-server"
bin = "./tmp/marka-server" bin = "./tmp/marka-server"
# Command to run the application with arguments. # Command to run the application with arguments.
full_bin = "./tmp/marka-server -root=/home/max/Notes/resources -addr=:8080 -playground-root=./playground" full_bin = "MARKA_API_KEY='SECRET' ./tmp/marka-server -root=/home/max/Notes/resources -addr=:8080 -playground-root=./playground"
# Watch these file extensions. # Watch these file extensions.
include_ext = ["go", "http"] include_ext = ["go", "http"]

View File

@@ -2,6 +2,7 @@ package main
import ( import (
"flag" "flag"
"fmt"
"log" "log"
"net/http" "net/http"
"os" "os"
@@ -62,6 +63,7 @@ func main() {
must(err) must(err)
apiKey := os.Getenv("MARKA_API_KEY") apiKey := os.Getenv("MARKA_API_KEY")
fmt.Println(apiKey)
http.Handle("/", handler.NewHandler(fsAdapter, apiKey)) http.Handle("/", handler.NewHandler(fsAdapter, apiKey))
log.Printf("listening on %s, roots=%s", *addr, strings.Join(absRoots, ", ")) log.Printf("listening on %s, roots=%s", *addr, strings.Join(absRoots, ", "))

View File

@@ -2,6 +2,7 @@
package handler package handler
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@@ -62,16 +63,16 @@ func (h *Handler) post(w http.ResponseWriter, r *http.Request, target string) {
body, err := io.ReadAll(r.Body) body, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
writeError(w, http.StatusBadRequest, err) writeError(w, http.StatusBadRequest, fmt.Errorf("failed to decode body: %w", err))
return return
} }
defer r.Body.Close() defer r.Body.Close()
contentType := r.Header.Get("Content-Type") contentType := r.Header.Get("Content-Type")
isJSON := strings.HasPrefix(contentType, "application/json") isResource := strings.HasPrefix(contentType, "application/json") && strings.HasSuffix(target, ".md")
var contentToWrite []byte var contentToWrite []byte
if strings.HasSuffix(target, ".md") && isJSON { if isResource {
renderedContent, err := renderer.RenderFile(body) renderedContent, err := renderer.RenderFile(body)
if err != nil { if err != nil {
writeError(w, http.StatusInternalServerError, fmt.Errorf("failed to render file: %w", err)) writeError(w, http.StatusInternalServerError, fmt.Errorf("failed to render file: %w", err))
@@ -87,7 +88,17 @@ func (h *Handler) post(w http.ResponseWriter, r *http.Request, target string) {
return return
} }
w.WriteHeader(http.StatusNoContent) if isResource {
var data map[string]any
if err := json.Unmarshal(body, &data); err != nil && strings.HasSuffix(target, ".md") {
writeError(w, http.StatusInternalServerError, fmt.Errorf("failed to decode body: %w", err))
return
}
writeJSON(w, http.StatusOK, data)
return
}
writeJSON(w, http.StatusOK, map[string]any{"success": true})
} }
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -98,6 +109,8 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
target := cleanURLLike(reqPath) target := cleanURLLike(reqPath)
fmt.Printf("[serve] %s %s\n", r.Method, target)
switch r.Method { switch r.Method {
case http.MethodGet: case http.MethodGet:
h.get(w, target) h.get(w, target)