Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge fixes #326

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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