| 272 | self.cp_shutdown_event.set() |
| 273 | |
| 274 | def run(self) -> None: |
| 275 | self.log.info("node-proxy API configuration...") |
| 276 | cherrypy.config.update( |
| 277 | { |
| 278 | "environment": "production", |
| 279 | "engine.autoreload.on": False, |
| 280 | "log.screen": True, |
| 281 | } |
| 282 | ) |
| 283 | config = { |
| 284 | "/": { |
| 285 | "request.methods_with_bodies": ("POST", "PUT", "PATCH"), |
| 286 | "tools.trailing_slash.on": False, |
| 287 | "tools.auth_basic.realm": "localhost", |
| 288 | "tools.auth_basic.checkpassword": self.check_auth, |
| 289 | } |
| 290 | } |
| 291 | cherrypy.tree.mount(self.api, "/", config=config) |
| 292 | # cherrypy.tree.mount(admin, '/admin', config=config) |
| 293 | |
| 294 | ssl_crt = write_tmp_file(self.ssl_crt, prefix_name="listener-crt-") |
| 295 | ssl_key = write_tmp_file(self.ssl_key, prefix_name="listener-key-") |
| 296 | |
| 297 | self.api.ssl_certificate = ssl_crt.name |
| 298 | self.api.ssl_private_key = ssl_key.name |
| 299 | |
| 300 | cherrypy.server.unsubscribe() |
| 301 | try: |
| 302 | cherrypy.engine.start() |
| 303 | self.log.info("node-proxy API started.") |
| 304 | self.cp_shutdown_event.wait() |
| 305 | self.cp_shutdown_event.clear() |
| 306 | cherrypy.engine.exit() |
| 307 | cherrypy.server.httpserver = None |
| 308 | self.log.info("node-proxy API shutdown.") |
| 309 | except Exception as e: |
| 310 | self.log.error(f"node-proxy API error: {e}") |