Skip to content

Commit

Permalink
Merge pull request #326 from HapticX/dev
Browse files Browse the repository at this point in the history
merge fixes
  • Loading branch information
Ethosa authored Aug 6, 2024
2 parents 8895b6b + 6a9c029 commit 840cb54
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/happyx/spa/tag.nim
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ when defined(js):
const _originCloneNode = Node.prototype.cloneNode;
Node.prototype.__getEventIndex = function(target, targetArgs) {
if (!this._eventListeners)
if (!this._eventListeners) {
this._eventListeners = [];
return -1;
}
if (!targetArgs) return -1;
return this._eventListeners.findIndex(args => {
for (let i = 0; i < args.length; i++)
if (targetArgs[i] !== args[i]) return false;
Expand Down Expand Up @@ -598,12 +601,12 @@ func `$`*(self: TagRef): string =
argsStr = self.args.join(" ")

if self.isText:
return self.name
return xmltree.escape(self.name)

var attrs = ""
for key, value in self.attrs.pairs():
if value.len > 0:
attrs &= " " & key & "=" & "\"" & value & "\""
attrs &= " " & key & "=" & "\"" & value.replace("\"", "&quot;") & "\""
else:
attrs &= " " & key

Expand Down Expand Up @@ -932,12 +935,12 @@ when defined(js):
argsStr = self.args.join(" ")

if self.isText:
return self.name
return xmltree.escape(self.name)

var attrs = ""
for key, value in self.attrs.pairs():
if value.len > 0:
attrs &= " " & key & "=" & "\"" & value & "\""
attrs &= " " & key & "=" & "\"" & value.replace("\"", "&quot;") & "\""
else:
attrs &= " " & key

Expand Down
10 changes: 8 additions & 2 deletions src/happyx/ssr/cors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ when not defined(js) and not (exportJvm or exportPython or defined(napibuild)):
if `allowMethods`.len > 0:
`headers`["Access-Control-Allow-Methods"] = `allowMethods`
if `allowOrigins`.len > 0:
`headers`["Access-Control-Allow-Origin"] = `allowOrigins`
if `allowOrigins` == @["*"]:
when not enableHttpx and not enableHttpBeast:
`headers`["Access-Control-Allow-Origin"] = req.hostname
else:
`headers`["Access-Control-Allow-Origin"] = req.ip
else:
`headers`["Access-Control-Allow-Origin"] = `allowOrigins`

macro regCORS*(body: untyped): untyped =
## Register CORS
Expand Down Expand Up @@ -148,7 +154,7 @@ else:
if cors.allowOrigins.len > 0:
for origin in cors.allowOrigins:
if origin == "*":
`headers`["Access-Control-Allow-Origin"] = "*"
`headers`["Access-Control-Allow-Origin"] = host
break
elif origin == `host`:
`headers`["Access-Control-Allow-Origin"] = origin
Expand Down
5 changes: 5 additions & 0 deletions tests/testc20.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ serve("127.0.0.1", 5000):
post "/[data:Obj:json]":
echo data
return ""

get "/":
buildHtml:
tDiv(class="hello\" style=\"color:green"):
"hello <b>world</b>"

get "/issue287":
statusCode = 200
Expand Down
2 changes: 1 addition & 1 deletion tests/testc6.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import

regCORS:
credentials: true
origins: "https://www.google.com" # You can send request from this address
origins: "*" # "https://www.google.com" # You can send request from this address
methods: ["GET", "POST", "PUT"]
headers: "*"

Expand Down
17 changes: 17 additions & 0 deletions tests/testjs18.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,25 @@ let C = buildHtml:
text(x="35",y="20", style= "fill: black;"): "C: Anyone Here?"


component Hello:
html:
tDiv:
"hello"

let b = buildHtml:
Hello

let c = buildHtml:
tDiv:
"hello"


appRoutes("app"):
"/":
tDiv: {$b}
tDiv:
{$c}
c
for i in 1..5:
tDiv:
{$htmlProcs[0]()}
Expand Down

0 comments on commit 840cb54

Please sign in to comment.