socketify.py/src/tests.py

27 wiersze
614 B
Python
Czysty Zwykły widok Historia

2023-01-03 21:05:49 +00:00
from socketify import App
2022-10-24 17:15:46 +00:00
2023-01-03 21:05:49 +00:00
app = App()
2022-10-24 17:15:46 +00:00
2023-01-03 21:05:49 +00:00
def extension(request, response, ws):
2022-11-08 10:17:51 +00:00
2023-01-03 21:05:49 +00:00
@request.method
async def get_user(self):
token = self.get_header("token")
self.token = token
return { "name": "Test" } if token else { "name", "Anonymous" }
2023-01-03 21:05:49 +00:00
@request.method
async def get_cart(self):
return [{ "quantity": 10, "name": "T-Shirt" }]
2022-11-01 12:30:46 +00:00
2023-01-03 21:05:49 +00:00
request.property("token", None)
2023-01-03 21:05:49 +00:00
app.register(extension)
2022-11-16 19:28:46 +00:00
2023-01-03 21:05:49 +00:00
app.get("/", lambda res, req: res.end("Hello World!"))
app.listen(
3000,
lambda config: print("Listening on port http://localhost:%d now\n" % config.port),
)
app.run()