diff --git a/tests/examples/https.py b/tests/examples/https.py new file mode 100644 index 0000000..cf7be96 --- /dev/null +++ b/tests/examples/https.py @@ -0,0 +1,18 @@ +from socketify import App, AppOptions + + +#this can be async no problems +def on_error(error, res, req): + #here you can log properly the error and do a pretty response to your clients + print("Somethind goes %s" % str(error)) + #response and request can be None if the error is in an async function + if res != None: + #if response exists try to send something + res.write_status(500) + res.end("Sorry we did something wrong") +app = App(AppOptions(key_file_name="./misc/key.pem", cert_file_name="./misc/cert.pem", passphrase="1234")) +app.set_error_handler(on_error) + +app.get("/", lambda res, req: res.end("Hello World socketify from Python!")) +app.listen(3000, lambda config: print("Listening on port https://localhost:%d now\n" % config.port)) +app.run() \ No newline at end of file diff --git a/tests/examples/listen_options.py b/tests/examples/listen_options.py new file mode 100644 index 0000000..b85be5b --- /dev/null +++ b/tests/examples/listen_options.py @@ -0,0 +1,6 @@ +from socketify import App, AppListenOptions + +app = App() +app.get("/", lambda res, req: res.end("Hello World socketify from Python!")) +app.listen(AppListenOptions(port=3000, host="0.0.0.0"), lambda config: print("Listening on port http://%s:%d now\n" % (config.host, config.port))) +app.run() \ No newline at end of file diff --git a/misc/crt.pem b/tests/examples/misc/crt.pem similarity index 100% rename from misc/crt.pem rename to tests/examples/misc/crt.pem diff --git a/misc/key.pem b/tests/examples/misc/key.pem similarity index 100% rename from misc/key.pem rename to tests/examples/misc/key.pem