app-const.py 781 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import multiprocessing
  2. import os
  3. from robyn import Response, Robyn, jsonify
  4. from robyn.argument_parser import Config
  5. class SpecialConfig(Config):
  6. def __init__(self):
  7. super().__init__()
  8. self.workers = 2
  9. self.processes = (os.cpu_count() * 2) + 1
  10. self.log_level = "WARN"
  11. app = Robyn(__file__, config=SpecialConfig())
  12. @app.get("/plaintext", const=True)
  13. def plaintext() -> str:
  14. return "Hello, world!"
  15. @app.get("/json", const=True)
  16. def json() -> str:
  17. return Response(
  18. status_code=200,
  19. description=jsonify({"message": "Hello, world!"}),
  20. headers={"Content-Type": "application/json"}
  21. )
  22. if __name__ == "__main__":
  23. app.add_response_header("Server", "Robyn")
  24. app.start(host="0.0.0.0", port=8080)