sanic/tests/performance/wheezy/simple_server.py
Adam Hopkins 2a44a27236
Backport to 1912 (#1900)
* Cherry pick PRs to backport to 19.12LTS

Includes commits from:
https://github.com/huge-success/sanic/pull/1762
https://github.com/huge-success/sanic/pull/1764
https://github.com/huge-success/sanic/pull/1789

* Fix type annotation issue; run black and isort

* Update Makefile

Co-authored-by: Ashley Sommer <ashleysommer@gmail.com>
2020-07-29 13:54:33 +03:00

51 lines
1.2 KiB
Python

# Run with: gunicorn --workers=1 --worker-class=meinheld.gmeinheld.MeinheldWorker simple_server:main
""" Minimal helloworld application.
"""
import ujson
from wheezy.http import HTTPResponse, WSGIApplication
from wheezy.http.response import json_response
from wheezy.routing import url
from wheezy.web.handlers import BaseHandler
from wheezy.web.middleware import (
bootstrap_defaults,
path_routing_middleware_factory,
)
class WelcomeHandler(BaseHandler):
def get(self):
response = HTTPResponse(content_type="application/json; charset=UTF-8")
response.write(ujson.dumps({"test": True}))
return response
all_urls = [
url("", WelcomeHandler, name="default"),
# url('', welcome, name='welcome')
]
options = {}
main = WSGIApplication(
middleware=[
bootstrap_defaults(url_mapping=all_urls),
path_routing_middleware_factory,
],
options=options,
)
if __name__ == "__main__":
import sys
from wsgiref.simple_server import make_server
try:
print("Visit http://localhost:{}/".format(sys.argv[-1]))
make_server("", int(sys.argv[-1]), main).serve_forever()
except KeyboardInterrupt:
pass
print("\nThanks!")