2016-10-15 07:31:47 +01:00
|
|
|
# Run with: gunicorn --workers=1 --worker-class=meinheld.gmeinheld.MeinheldWorker simple_server:main
|
|
|
|
""" Minimal helloworld application.
|
|
|
|
"""
|
2019-04-23 22:44:42 +01:00
|
|
|
import ujson
|
|
|
|
|
|
|
|
from wheezy.http import HTTPResponse, WSGIApplication
|
2016-10-15 07:31:47 +01:00
|
|
|
from wheezy.routing import url
|
|
|
|
from wheezy.web.handlers import BaseHandler
|
2019-04-23 22:44:42 +01:00
|
|
|
from wheezy.web.middleware import (
|
|
|
|
bootstrap_defaults,
|
|
|
|
path_routing_middleware_factory,
|
|
|
|
)
|
2016-10-15 07:31:47 +01:00
|
|
|
|
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
class WelcomeHandler(BaseHandler):
|
2016-10-15 07:31:47 +01:00
|
|
|
def get(self):
|
2018-12-30 11:18:06 +00:00
|
|
|
response = HTTPResponse(content_type="application/json; charset=UTF-8")
|
|
|
|
response.write(ujson.dumps({"test": True}))
|
2016-10-15 07:31:47 +01:00
|
|
|
return response
|
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
|
2016-10-15 07:31:47 +01:00
|
|
|
all_urls = [
|
2018-12-30 11:18:06 +00:00
|
|
|
url("", WelcomeHandler, name="default"),
|
|
|
|
# url('', welcome, name='welcome')
|
2016-10-15 07:31:47 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
options = {}
|
|
|
|
main = WSGIApplication(
|
|
|
|
middleware=[
|
|
|
|
bootstrap_defaults(url_mapping=all_urls),
|
2018-12-30 11:18:06 +00:00
|
|
|
path_routing_middleware_factory,
|
2016-10-15 07:31:47 +01:00
|
|
|
],
|
2018-12-30 11:18:06 +00:00
|
|
|
options=options,
|
2016-10-15 07:31:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-12-30 11:18:06 +00:00
|
|
|
if __name__ == "__main__":
|
2016-10-15 07:31:47 +01:00
|
|
|
import sys
|
2020-07-07 14:13:03 +01:00
|
|
|
|
2016-10-15 07:31:47 +01:00
|
|
|
from wsgiref.simple_server import make_server
|
2018-12-30 11:18:06 +00:00
|
|
|
|
2016-10-15 07:31:47 +01:00
|
|
|
try:
|
2018-12-30 11:18:06 +00:00
|
|
|
print("Visit http://localhost:{}/".format(sys.argv[-1]))
|
|
|
|
make_server("", int(sys.argv[-1]), main).serve_forever()
|
2016-10-15 07:31:47 +01:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
2018-12-30 11:18:06 +00:00
|
|
|
print("\nThanks!")
|