Skip to content

Commit

Permalink
app base path
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen committed Oct 26, 2024
1 parent 7ffd6bf commit 0e76fa2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/api/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ By default, this is not enabled. You can enable this by setting it to `true`.

This uses WebSockets instead of HTTP Server-Sent Events (SSE) as the transport protocol for UI updates. If you set this environment variable to `true`, then [`MESOP_CONCURRENT_UPDATES_ENABLED`](#MESOP_CONCURRENT_UPDATES_ENABLED) will automatically be enabled as well.

### MESOP_STATIC_FILES_BASE_PATH
### MESOP_APP_BASE_PATH

This is the base path for serving static files. This is rarely needed because the default of using os.getcwd() is usually sufficient.
This is the base path used to resolve other paths, particularly for serving static files. This is rarely needed because the default of using os.getcwd() is usually sufficient.

## Usage Examples

Expand Down
4 changes: 1 addition & 3 deletions mesop/env/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"MESOP_AI_SERVICE_BASE_URL", "http://localhost:43234"
)

MESOP_STATIC_FILES_BASE_PATH = os.environ.get(
"MESOP_STATIC_FILES_BASE_PATH", ""
)
MESOP_APP_BASE_PATH = os.environ.get("MESOP_APP_BASE_PATH", "")

MESOP_WEBSOCKETS_ENABLED = (
os.environ.get("MESOP_WEBSOCKETS_ENABLED", "false").lower() == "true"
Expand Down
6 changes: 3 additions & 3 deletions mesop/labs/web_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from functools import wraps
from typing import Any, Callable, TypeVar, cast

from mesop.env.env import MESOP_STATIC_FILES_BASE_PATH
from mesop.env.env import MESOP_APP_BASE_PATH
from mesop.runtime import runtime
from mesop.utils.validate import validate

Expand Down Expand Up @@ -53,8 +53,8 @@ def format_filename(filename: str) -> str:
if ".runfiles" in filename:
# Handle Bazel case
return filename.split(".runfiles", 1)[1]
elif MESOP_STATIC_FILES_BASE_PATH:
return os.path.relpath(filename, MESOP_STATIC_FILES_BASE_PATH)
elif MESOP_APP_BASE_PATH:
return os.path.relpath(filename, MESOP_APP_BASE_PATH)
else:
# Handle pip CLI case
return os.path.relpath(filename, os.getcwd())
6 changes: 3 additions & 3 deletions mesop/server/static_file_serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from flask import Flask, Response, g, make_response, request, send_file
from werkzeug.security import safe_join

from mesop.env.env import MESOP_STATIC_FILES_BASE_PATH
from mesop.env.env import MESOP_APP_BASE_PATH
from mesop.exceptions import MesopException
from mesop.runtime import runtime
from mesop.server.constants import WEB_COMPONENTS_PATH_SEGMENT
Expand Down Expand Up @@ -100,8 +100,8 @@ def serve_web_components(path: str):
else safe_join(os.getcwd(), path)
)

if MESOP_STATIC_FILES_BASE_PATH:
serving_path = safe_join(MESOP_STATIC_FILES_BASE_PATH, path)
if MESOP_APP_BASE_PATH:
serving_path = safe_join(MESOP_APP_BASE_PATH, path)

file_name = os.path.basename(path)
file_extension = os.path.splitext(file_name)[1].lower()
Expand Down

0 comments on commit 0e76fa2

Please sign in to comment.