Commit 1b5ab4bafff3b7e26bb475e1f389afb132b61390
1 parent
3de42468
Exists in
dev
delete redirect.py (not using it)
Showing
2 changed files
with
4 additions
and
49 deletions
Show diff stats
aprendizations/main.py
... | ... | @@ -172,7 +172,10 @@ def main(): |
172 | 172 | logger.info('LearnApp started') |
173 | 173 | |
174 | 174 | # --- run webserver forever ---------------------------------------------- |
175 | - asyncio.run(webserver(app=app, ssl=ssl_ctx, port=arg.port, debug=arg.debug)) | |
175 | + asyncio.run(webserver(app=app, | |
176 | + ssl=ssl_ctx, | |
177 | + port=arg.port, | |
178 | + debug=arg.debug)) | |
176 | 179 | logger.critical('Webserver stopped.') |
177 | 180 | |
178 | 181 | ... | ... |
aprendizations/redirect.py
... | ... | @@ -1,48 +0,0 @@ |
1 | -#!/usr/bin/env python3 | |
2 | - | |
3 | -# python standard libraries | |
4 | -import argparse | |
5 | - | |
6 | -# third party libraries | |
7 | -from tornado.web import RedirectHandler, Application | |
8 | -from tornado.ioloop import IOLoop | |
9 | - | |
10 | - | |
11 | -def main(): | |
12 | - default_url = 'https://bit.xdi.uevora.pt/' | |
13 | - default_port = 8080 | |
14 | - | |
15 | - # --- Commandline argument parsing | |
16 | - argparser = argparse.ArgumentParser( | |
17 | - description='Redirection server. ' | |
18 | - 'Listen on a given port for HTTP requests and responds with a ' | |
19 | - '301 - Moved Permanently - so that the browser is redirected to the ' | |
20 | - 'correct target address.' | |
21 | - ) | |
22 | - argparser.add_argument( | |
23 | - '-p', '--port', type=int, default=default_port, | |
24 | - help=f'Port to listen to (default: {default_port})' | |
25 | - ) | |
26 | - argparser.add_argument( | |
27 | - '-t', '--target', type=str, default=default_url, | |
28 | - help=f'Target address (default: {default_url})' | |
29 | - ) | |
30 | - arg = argparser.parse_args() | |
31 | - print(f'Redirecting from port {arg.port} to {arg.target}') | |
32 | - | |
33 | - # --- run server | |
34 | - handlers = [(r'.*', RedirectHandler, {'url': arg.target})] | |
35 | - app = Application(handlers) | |
36 | - app.listen(arg.port) | |
37 | - | |
38 | - try: | |
39 | - IOLoop.current().start() # running... | |
40 | - except Exception: | |
41 | - IOLoop.current().stop() | |
42 | - | |
43 | - print('Redirection stopped!') | |
44 | - | |
45 | - | |
46 | -# ---------------------------------------------------------------------------- | |
47 | -if __name__ == "__main__": | |
48 | - main() |