PyWebIO icon indicating copy to clipboard operation
PyWebIO copied to clipboard

How to add HTTPS functionality to a pywebio web server?

Open MinaGithuub opened this issue 3 years ago • 4 comments

How to add HTTPS functionality to a pywebio web server?

MinaGithuub avatar May 18 '22 20:05 MinaGithuub

+1

AxelZschutschke avatar Jun 21 '22 12:06 AxelZschutschke

+1

TimoRJensen avatar Jul 28 '22 11:07 TimoRJensen

Found the solution:

(relevant code snippet of my Application class -> for webio_handler(self) you need to implement the call(self) method, where your pywebio code resides)

    def __call__(self):
        pass

    def startup(self):
        if not self.certfile or not self.keyfile:
            self.log.error("please provide ssl key/cert files via config")
            return
        if not self.dbpath or not self.db:
            self.log.error("please provide a valid database path via config")
            return

        tornadowebapp = tornado.web.Application([
            (r"/database/(.*)", tornado.web.StaticFileHandler, {"path": self.dbpath }),
            (r"/(.*)", webio_handler(self)),
        ])
        http_server = tornado.httpserver.HTTPServer(tornadowebapp, ssl_options={"certfile":self.certfile,"keyfile":self.keyfile} )
        http_server.listen(port=self.port)
        tornado.ioloop.IOLoop.instance().start()

AxelZschutschke avatar Jul 29 '22 06:07 AxelZschutschke

much appreciated, thanks for sharing!

TimoRJensen avatar Jul 29 '22 06:07 TimoRJensen