ngrok / ngrok-python

Embed ngrok secure ingress into your Python apps with a single line of code.
https://ngrok.com
Apache License 2.0
103 stars 19 forks source link

how to pass edge/labels and other tunnel/forwarding params in the Django example? #87

Closed jimkring closed 5 months ago

jimkring commented 6 months ago

I found a stub/placeholder document for using ngrok with django and also found a django example here in the sources.

However, I couldn't figure out how/where to add labels='edge:edge_yadayada...' into the configuration for the listener.

Neither the ngrok.default() nor the listener.forward() methods (shown below, in a snippet from the django example) support a labels argument. Where would these various parameters be passed, which are generally designed to be passed to ngrok.forward()?

...
listener = await ngrok.default()
...
listener.forward(listen)
...

Thanks,

bobzilladev commented 5 months ago

Sure, the label options can be set on the listener using builder configuration. Taking some bits from the ngrok-labeled.py example, that would look something like this in that djangosite example, replacing the ngrok.default() convenience function:

session = await ngrok.SessionBuilder().authtoken_from_env().connect()
listener = await session.labeled_listener().label("edge", "edghts_<edge_id>").listen()
print(f"Forwarding to {listen} from ingress id: {listener.id()}")

The label(label, value) can be called multiple times to add more label pairs. Hopefully that will work for your use case! Thank you for the feedback around working with Edges.

bobzilladev commented 5 months ago

Hi there, hopefully that example was helpful in getting the labeled tunnels to work in Django, going to close out this ticket, feel free to reopen if there are any other questions or issues. Thanks for writing in!