class_docstr: Resource class to serve frontend files.
class_docstr_tok: ["Resource","class","to","serve","frontend","files","."]
docstr: Hack HTML and Javascript files to setup backend if necessary.
docstr_tok: ["Hack","HTML","and","Javascript","files","to","setup","backend","if","necessary","."]
code: def on_get(self, req, resp):
      """Hack HTML and Javascript files to setup backend if necessary."""
      path = req.relative_uri.strip("/") or "index.html"
      file_path = os.path.join(self.STATIC_DIR, path)
      if os.path.isfile(file_path):
          content_type, _ = mimetypes.guess_type(file_path)
          resp.status = falcon.HTTP_200
          resp.content_type = content_type
          with open(file_path, "rb") as file:
              content = file.read()
              if content_type in self.TEXT_TYPES:
                  content = content.decode()
                  if (
                      self.backend is not None
                      and self.PLACEHOLDER in content
                  ):
                      content = content.replace(
                          self.PLACEHOLDER, repr(self.backend)
                      )
              resp.body = content
      else:
          resp.status = falcon.HTTP_404
  
file_path: orion/src/orion/core/cli/frontend.py
imports: import logging
  import mimetypes
  import os
  import site
  import sys
  import falcon
  from gunicorn.app.base import BaseApplication
label_desc: Use image node_id 2 for calling the StaticResource obj's underlying member method code with example usage: obj.on_get(req, resp) without return types