sfun commited on
Commit
4070c52
1 Parent(s): 12a325d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -114,12 +114,8 @@ async def handle_request(request):
114
  else:
115
  return web.Response(text="Not Found", status=404)
116
 
117
- async def init_app():
118
- app = web.Application(middlewares=[web.middleware(lambda _, handler: logging_middleware(handler))])
119
- app.router.add_get('/', handle_request)
120
- return app
121
-
122
- async def logging_middleware(handler, request):
123
  start_time = datetime.datetime.now()
124
  try:
125
  response = await handler(request)
@@ -135,6 +131,11 @@ async def logging_middleware(handler, request):
135
  traceback.print_exc()
136
  return web.Response(text=f"Internal Server Error: {str(e)}", status=500)
137
 
 
 
 
 
 
138
  if __name__ == "__main__":
139
  print(f"===== Application Startup at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} =====")
140
  print("Server running on port 8080")
 
114
  else:
115
  return web.Response(text="Not Found", status=404)
116
 
117
+ @web.middleware
118
+ async def logging_middleware(request, handler):
 
 
 
 
119
  start_time = datetime.datetime.now()
120
  try:
121
  response = await handler(request)
 
131
  traceback.print_exc()
132
  return web.Response(text=f"Internal Server Error: {str(e)}", status=500)
133
 
134
+ async def init_app():
135
+ app = web.Application(middlewares=[logging_middleware])
136
+ app.router.add_get('/', handle_request)
137
+ return app
138
+
139
  if __name__ == "__main__":
140
  print(f"===== Application Startup at {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} =====")
141
  print("Server running on port 8080")