You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 rivejä
1.5 KiB

  1. import sys, os
  2. import json
  3. sys.path.insert(0, '.')
  4. sys.path.insert(0, 'app')
  5. sys.path.insert(0, 'lib')
  6. from werkzeug.wrappers import Request, Response
  7. from werkzeug.local import LocalManager
  8. from webnotes.middlewares import StaticDataMiddleware
  9. from werkzeug.exceptions import HTTPException
  10. from webnotes import get_config
  11. import mimetypes
  12. import webnotes
  13. import webnotes.handler
  14. import webnotes.auth
  15. import webnotes.webutils
  16. local_manager = LocalManager([webnotes.local])
  17. @Request.application
  18. def application(request):
  19. webnotes.local.request = request
  20. try:
  21. site = webnotes.utils.get_site_name(request.host)
  22. webnotes.init(site=site)
  23. webnotes.local.form_dict = webnotes._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \
  24. for k, v in (request.form or request.args).iteritems() })
  25. webnotes.local._response = Response()
  26. try:
  27. webnotes.http_request = webnotes.auth.HTTPRequest()
  28. except webnotes.AuthenticationError, e:
  29. pass
  30. if webnotes.form_dict.cmd:
  31. webnotes.handler.handle()
  32. else:
  33. webnotes.webutils.render(webnotes.request.path[1:])
  34. except HTTPException, e:
  35. return e
  36. finally:
  37. if webnotes.conn:
  38. webnotes.conn.close()
  39. return webnotes._response
  40. application = local_manager.make_middleware(application)
  41. application = StaticDataMiddleware(application, {
  42. '/': 'public',
  43. })
  44. def serve(port=8000):
  45. from werkzeug.serving import run_simple
  46. run_simple('0.0.0.0', int(port), application, use_reloader=True,
  47. use_debugger=True, use_evalex=True)