i am working on a web server in python that uses ngrok (pyngrok). this generates new URLs every time i restart the code, making the URL redundant as i am constantly implementing changes. is there a workaround to this? now what i need is one master URL which redirects to another my generated URL that can be updated each time the URL is generated. let me know if my problem is not clear or if you know a solution
-
Please update your question to specify which web framework you are using, otherwise we really can't confidently answer the question for you. Then I will update my answer to be more specific to your use case. – alexdlaird Jul 09 '20 at 20:47
-
Appears you're new to Stack Overflow, so just a friendly reminder to click the checkmark on answers to the benefit community members that helped you out. – alexdlaird Aug 27 '20 at 16:51
1 Answers
You don't specify the web framework you're using, which is pretty crucial to answer the question. However, I can still provide some clarity to help you understand why this is happening.
Most popular frameworks come with a dev server, and this dev server forks itself when it starts. This is so one thread can manage the server and the other thread can watch for file changes–when a file change is detected, the thread managing the server gets kicked and restarted so your changes are immediately seen. You want pyngrok
to run in the other thread, the parent thread, the one watching for file changes, as this thread is long-lived and does not get restarted (thus your ngrok
URL will also be long-lived).
The pyngrok
documentation has several integration examples for (Flask, Django, and others) that show you how to start pyngrok
in this way. You can find them here, but the short of it is, if you're using Flask you only want to start pyngrok
when os.environ.get("WERKZEUG_RUN_MAIN") != "true"
, and if you're using Django you only want to start pyngrok
when os.environ.get("RUN_MAIN", None) != "true"
.
Let me know if it's another web framework that you're using and I can provide more examples.
Full disclosure, I am the developer of pyngrok
.

- 1,174
- 12
- 34
-
oh i completeley forgot about this question but i managed to work around it by changing the cname recored of my dns using an api to the new generated url every time – ZyugyZarc Aug 31 '20 at 03:25