manatlan / guy

Graphics User Ynterface : a simple module for making GUI applications (with html/js) for py3 ... to target windows, linux, mac & android
Apache License 2.0
202 stars 23 forks source link

Added ability to customize web server #11

Closed dferens closed 4 years ago

dferens commented 4 years ago

Hi,

I simply added a reference to a tornado server instance so I'm able to customize it, like add handlers.

What do you think about it?

manatlan commented 4 years ago

Good idea ! I take

manatlan commented 4 years ago

it's in this repo !

inillaug commented 4 years ago

Can you please post a little example for direct interaction with tornado? Thanks in advance.

manatlan commented 4 years ago

Better ask @dferens ... It's just a "simple hack" (currently) ... which give the ability to interact with the tornado app instance (tornado.web.Application) in a self "app" property ... BTW, the "self.app" is (currently) only visible when it's running.

I don't have tried it yet ... but should work as is ... I imagine that you can add/remove routes to handlers ... or something like that

dferens commented 4 years ago

Sorry guys, but I'm not using this project anymore. After seeing this code I ended up writing my own project.

manatlan commented 4 years ago

You're right ... it's awful ... (but it's true, currently, I don't understand why I must do that) But I promess you; i will work on this point in a future release ...

Keep in mind, that it's a personnal project ... and I've got a lot of private project that use it, as is ... Sure, it's not developped a pro fashion ;-) ... Currently, it's more empirical/pragmatic way ;-) But I will make effort ...

happy to see other project going in the same direction ! no trouble !

inillaug commented 4 years ago

The only thing I need by tornado is to have the IP address of the connected client. I want to show that value in the webpage of the connected client.

PS: The place of the documentation "https://guy-docs.glitch.me/" is very often unavailable.

manatlan commented 4 years ago

sadly, you can't get the exposed ip from the socket client ... (perhaps in future version) But with the http decorator, it's do'able, like this :

#!/usr/bin/python3 -u
# -*- coding: utf-8 -*-
import guy

class Server(guy.Guy):
   """<a href="/whatIsMyIp">test whatIsMyIp</a>"""

@guy.http("/whatIsMyIp")
def test(web):
    ip = web.request.headers.get("X-Real-IP") or web.request.headers.get("X-Forwarded-For") or web.request.remote_ip
    print(ip)

if __name__ == "__main__":
    Server().serve()