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

Found Bug 🐛: Auth and Cached decorators not working with Mounts #383

Closed
Beetroit opened this issue Dec 18, 2024 · 6 comments · Fixed by #384
Closed

Found Bug 🐛: Auth and Cached decorators not working with Mounts #383

Beetroit opened this issue Dec 18, 2024 · 6 comments · Fixed by #384
Labels
bug Something isn't working

Comments

@Beetroit
Copy link
Contributor

Describe the bug 🐛
I use a mount in my api, the code is defined in another file and then mounted. When i try to use either of the new auth decorators, or the new cached one, i get a weird error. It happens whether i'm using the decorator in the mount but not from the main server file.

To Reproduce 👨‍🔬
Steps to reproduce the behavior:

  1. Create a basic ssr server
  2. Add some code in another file (so you can mount it)
  3. Try to use AuthBearerJWT, AuthJWT, or the Cached decorators on a route inside the mount file.
  4. See error

Expected behavior 🤔
Mounts should work fine with the new decorators.

Screenshots 🖼
image

image
This is from the mount file.

Please complete the following information 📃

  • OS: WIN 11 PRO 23H2 + WSL 2 ( Ubuntu 22.04)
  • HappyX version 4.7.0
  • HappyX project type [ssr/spa]
  • HappyX project language = Nim
  • Nim version = 2.2.0
  • HTTP Server Default (also fails on others too, tested on httpx and httpbeast)
@Beetroit Beetroit added the bug Something isn't working label Dec 18, 2024
Ethosa added a commit that referenced this issue Dec 18, 2024
@Ethosa Ethosa closed this as completed Dec 18, 2024
@Ethosa Ethosa mentioned this issue Dec 18, 2024
Ethosa added a commit that referenced this issue Dec 18, 2024
@Beetroit
Copy link
Contributor Author

Thanks for your prompt response. The cached decorator now throws an error when used in a mount.
image

It works fine from inside the main file, just not from a mounted one.

@Ethosa
Copy link
Contributor

Ethosa commented Dec 18, 2024

@Beetroit can you provide some example of code?

@Ethosa
Copy link
Contributor

Ethosa commented Dec 18, 2024

since a8740fb this works fine:

mount Profile:
  @AuthJWT
  @RateLimit
  get "/":
    ## Profile main page
    return "Hello, world!"
  
  @RateLimit(perSecond = 5)
  get "/rate-limit-test":
    ## Profile settings
    # echo rateLimits[key]
    return "Hello, world"
  
  get "/cached-test":
    ## Profile settings
    return "Hello, world"


serve "127.0.0.1", 5000:
  @Cached(10)
  mount "/profile" -> Profile

And this also works fine:

mount Profile:
  @Cached(10)
  get "/cached-test":
    ## Profile settings
    return "Hello, world"


serve "127.0.0.1", 5000:
  mount "/profile" -> Profile

@Beetroit
Copy link
Contributor Author

Beetroit commented Dec 18, 2024

main.nim file

import happyx
import test_case

serve "127.0.0.1", 5000:
    onException:
        echo e.msg
        echo e.name
        return {"error": getCurrentExceptionMsg()}
    
    notFound:
        return {"response": "Not found"}

    get "/":
        "Hello, World!"

    mount "/users" -> User

test_case.nim file

import happyx

mount User:
    get "/":
        return {"response": "Hello, World!"}

    # This works
    @Cached(10)
    get "/testcache":
        return "Cache"

    # This fails
    # @Cached(10)
    # get "/testcache":
    #     return {"response":  "Cache"}


nim.cfg

verbosity=0
hints=off
define = release
define = ssl
threads = on
deepcopy=on
define=beast

EDIT: The errors comes up when the cached decorator is used on a route that's returning json, but not for plaintext.

@Ethosa
Copy link
Contributor

Ethosa commented Dec 18, 2024

define=beast

does it works with define=httpx?

@Beetroit
Copy link
Contributor Author

nope

Ethosa added a commit that referenced this issue Dec 19, 2024
@Ethosa Ethosa mentioned this issue Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants