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

Defining handlers inside a module #198

Open
thevolatilebit opened this issue May 27, 2024 · 2 comments
Open

Defining handlers inside a module #198

thevolatilebit opened this issue May 27, 2024 · 2 comments

Comments

@thevolatilebit
Copy link

When I try to setup an API inside a module, it turns out that the handlers are not being registered. I have to define them outside the module to make it work.

Minimal example

Define inside a module

module BuildMyAPI

using Oxygen

function build_api(app=instance())
    app.get("/") do
        return "Hello World"
    end

    return app
end

end

using .BuildMyAPI: build_api

app = build_api()

# The route is not registered
app.serve(port=8010, async=true)

Define outside a module

using Oxygen

app = instance()

app.get("/") do
    return "Hello World"
end

# This works
app.serve(port=8010, async=true)
@ndortega
Copy link
Member

ndortega commented Jun 5, 2024

Hi @thevolatilebit,

Thanks for the code snippet, I'll have to take a look into that. In the meantime, I'd recommend using @oxidise macro to do the same for now (as long as the number of servers remains static).

https://github.com/OxygenFramework/Oxygen.jl/blob/master/demo/multiinstance.jl

The instance function has always been a bit hacky since it's dynamically creating a module at runtime in Julia which isn't encouraged (but still possible).

@thevolatilebit
Copy link
Author

I see, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants