Repository: HapticX/happyx (language: python)

Issue:
`staticDir` with addition headers
### Discussed in https://github.com/HapticX/happyx/discussions/222

<div type='discussions-op-text'>

<sup>Originally posted by **derekdai** December 19, 2023</sup>
How can I add more headers for `staticDir`? I tried with `middleware` + `outHeaders` but no use.</div>


Discussion / hints:
@derekdai 
Since latest commit you can use:

```nim
serve "127.0.0.1", 5000:
  staticDir "/testdir"

  middleware:
    outHeaders["x"] = "y"
```

Fix patch:
diff --git a/src/happyx/ssr/server.nim b/src/happyx/ssr/server.nim
index a7b2b130f..1776ff144 100755
--- a/src/happyx/ssr/server.nim
+++ b/src/happyx/ssr/server.nim
@@ -1089,7 +1089,12 @@ socketToSsr.onmessage=function(m){
                     bracket(extensions),
                     newCall("[]", newCall("split", directoryFromPath, newLit"."), newCall("^", newLit(1)))
                   ), newStmtList(
-                    newCall("await", newCall("answerFile", ident"req", directoryFromPath))
+                    newNimNode(nnkWhenStmt).add(newNimNode(nnkElifBranch).add(
+                      newCall("declared", ident"outHeaders"),
+                      newCall("await", newCall("answerFile", ident"req", directoryFromPath, newNimNode(nnkExprEqExpr).add(ident"headers", ident"outHeaders")))
+                    ), newNimNode(nnkElse).add(
+                      newCall("await", newCall("answerFile", ident"req", directoryFromPath))
+                    ))
                   )
                 ), newNimNode(nnkElse).add(
                   newCall(ident"answer", ident"req", newLit"Not found", ident"Http404")
@@ -1138,7 +1143,12 @@ socketToSsr.onmessage=function(m){
                     bracket(extensions),
                     newCall("[]", newCall("split", dirFromPath, newLit"."), newCall("^", newLit(1)))
                   ), newStmtList(
-                    newCall("await", newCall("answerFile", ident"req", dirFromPath))
+                    newNimNode(nnkWhenStmt).add(newNimNode(nnkElifBranch).add(
+                      newCall("declared", ident"outHeaders"),
+                      newCall("await", newCall("answerFile", ident"req", dirFromPath, newNimNode(nnkExprEqExpr).add(ident"headers", ident"outHeaders")))
+                    ), newNimNode(nnkElse).add(
+                      newCall("await", newCall("answerFile", ident"req", dirFromPath))
+                    ))
                   )
                 ), newNimNode(nnkElse).add(
                   newCall(ident"answer", ident"req", newLit"Not found", ident"Http404")


Test patch:
diff --git a/tests/testc20.nim b/tests/testc20.nim
index 2946a52f5..88467c745 100644
--- a/tests/testc20.nim
+++ b/tests/testc20.nim
@@ -15,5 +15,7 @@ serve "127.0.0.1", 5000:
   
   staticDir "/testdir"
 
+  staticDir "/testdir" -> "testdir" ~ "html,js,css"
+
   middleware:
-    outHeaders["x"] = "y"
\ No newline at end of file
+    outHeaders["x"] = "y"