Skip to content

Commit

Permalink
fix jvm binds
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Sep 3, 2024
1 parent c01d856 commit 125b303
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 100 deletions.
Binary file modified bindings/java/src/main/resources/happyx.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions src/happyx/ssr/cors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ else:
if cors.allowMethods.len > 0:
`headers`["Access-Control-Allow-Methods"] = cors.allowMethods
if cors.allowOrigins.len > 0:
if headers.hasKey("origin"):
if `headers`.hasKey("origin"):
for origin in cors.allowOrigins:
if origin == "*":
`headers`["Access-Control-Allow-Origin"] = headers["origin"]
`headers`["Access-Control-Allow-Origin"] = `headers`["origin"]
break
elif origin == `host`:
`headers`["Access-Control-Allow-Origin"] = origin
Expand Down
34 changes: 23 additions & 11 deletions src/happyx/ssr/server.nim
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,29 @@ proc newServer*(address: string = "127.0.0.1", port: int = 5000): Server =
var s = newServer()
assert s.address == "127.0.0.1"
{.cast(gcsafe).}:
result = Server(
address: address,
port: port,
components: newTable[string, BaseComponent](),
logger:
if loggerCreated:
newConsoleLogger(lvlNone, fgColored("[$date at $time]:$levelname ", fgYellow))
else:
loggerCreated = true
newConsoleLogger(lvlInfo, fgColored("[$date at $time]:$levelname ", fgYellow))
)
when enableDefaultComponents:
result = Server(
address: address,
port: port,
components: newTable[string, BaseComponent](),
logger:
if loggerCreated:
newConsoleLogger(lvlNone, fgColored("[$date at $time]:$levelname ", fgYellow))
else:
loggerCreated = true
newConsoleLogger(lvlInfo, fgColored("[$date at $time]:$levelname ", fgYellow))
)
else:
result = Server(
address: address,
port: port,
logger:
if loggerCreated:
newConsoleLogger(lvlNone, fgColored("[$date at $time]:$levelname ", fgYellow))
else:
loggerCreated = true
newConsoleLogger(lvlInfo, fgColored("[$date at $time]:$levelname ", fgYellow))
)
when enableHttpx or enableHttpBeast:
result.instance = initSettings(Port(port), bindAddr=address, numThreads = numThreads)
elif enableMicro:
Expand Down
264 changes: 177 additions & 87 deletions src/happyx/ssr/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,94 +29,184 @@ else:
import websocketx
export websocketx

when exportPython or defined(docgen):
import
nimpy,
../bindings/python_types

pyExportModule(name = "server", doc = """
HappyX web framework [SSR/SSG Part]
""")

type
Server* = ref object
address*: string
port*: int
routes*: seq[Route]
path*: string
parent*: Server
notFoundCallback*: PyObject
middlewareCallback*: PyObject
logger*: Logger
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
components*: TableRef[string, BaseComponent]
ModelBase* = ref object of PyNimObjectExperimental
elif exportJvm:
import ../bindings/java_types
when enableDefaultComponents:
when exportPython or defined(docgen):
import
nimpy,
../bindings/python_types

pyExportModule(name = "server", doc = """
HappyX web framework [SSR/SSG Part]
""")

type
Server* = ref object
address*: string
port*: int
routes*: seq[Route]
path*: string
parent*: Server
notFoundCallback*: PyObject
middlewareCallback*: PyObject
logger*: Logger
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
components*: TableRef[string, BaseComponent]
ModelBase* = ref object of PyNimObjectExperimental
elif exportJvm:
import ../bindings/java_types

type
Server* = ref object
address*: string
port*: int
logger*: Logger
path*: string
routes*: seq[Route]
parent*: Server
title*: string
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
components*: TableRef[string, BaseComponent]
ModelBase* = object of RootObj
elif defined(napibuild):
import denim except `%*`
import../bindings/node_types
type
Server* = ref object
address*: string
port*: int
logger*: Logger
path*: string
routes*: seq[Route]
parent*: Server
title*: string
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
components*: TableRef[string, BaseComponent]
ModelBase* = object of RootObj
elif defined(napibuild):
import denim except `%*`
import../bindings/node_types

type
Server* = ref object
address*: string
port*: int
logger*: Logger
path*: string
parent*: Server
routes*: seq[Route]
title*: string
environment*: napi_env
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
components*: TableRef[string, BaseComponent]
ModelBase* = object of RootObj
type
Server* = ref object
address*: string
port*: int
logger*: Logger
path*: string
parent*: Server
routes*: seq[Route]
title*: string
environment*: napi_env
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
components*: TableRef[string, BaseComponent]
ModelBase* = object of RootObj
else:
type
Server* = object
address*: string
port*: int
logger*: Logger
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
components*: TableRef[string, BaseComponent]
ModelBase* = object of RootObj
else:
type
Server* = object
address*: string
port*: int
logger*: Logger
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
components*: TableRef[string, BaseComponent]
ModelBase* = object of RootObj
when exportPython or defined(docgen):
import
nimpy,
../bindings/python_types

pyExportModule(name = "server", doc = """
HappyX web framework [SSR/SSG Part]
""")

type
Server* = ref object
address*: string
port*: int
routes*: seq[Route]
path*: string
parent*: Server
notFoundCallback*: PyObject
middlewareCallback*: PyObject
logger*: Logger
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
ModelBase* = ref object of PyNimObjectExperimental
elif exportJvm:
import ../bindings/java_types

type
Server* = ref object
address*: string
port*: int
logger*: Logger
path*: string
routes*: seq[Route]
parent*: Server
title*: string
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
ModelBase* = object of RootObj
elif defined(napibuild):
import denim except `%*`
import../bindings/node_types

type
Server* = ref object
address*: string
port*: int
logger*: Logger
path*: string
parent*: Server
routes*: seq[Route]
title*: string
environment*: napi_env
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
ModelBase* = object of RootObj
else:
type
Server* = object
address*: string
port*: int
logger*: Logger
when enableHttpx:
instance*: Settings
elif enableHttpBeast:
instance*: Settings
elif enableMicro:
instance*: MicroAsyncHttpServer
else:
instance*: AsyncHttpServer
ModelBase* = object of RootObj

0 comments on commit 125b303

Please sign in to comment.