Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
run-dev: Add option to host help center with starlight.
Shubham Padia7dfe68e0a252
diff --git a/tools/build-help-center b/tools/build-help-centernew file mode 100755index 00000000000..a4d0ea19455--- /dev/null+++ b/tools/build-help-center@@ -0,0 +1,4 @@+#!/usr/bin/env bash++./tools/convert-help-center-docs-to-mdx+(cd ./help-beta/ && /usr/local/bin/corepack pnpm build)diff --git a/tools/run-dev b/tools/run-devindex 4a3040a5722..ea405b7abf8 100755--- a/tools/run-dev+++ b/tools/run-dev@@ -8,6 +8,7 @@ import pwdimport signalimport subprocessimport sys+from collections.abc import Awaitable, CallableTOOLS_DIR = os.path.dirname(os.path.abspath(__file__))sys.path.insert(0, os.path.dirname(TOOLS_DIR))@@ -59,6 +60,9 @@ parser.add_argument(action="store_true",help="Start app server in HTTPS mode, using reverse proxy",)+parser.add_argument(+ "--help-center", action="store_true", help="Build and host help center with search"+)add_provision_check_override_param(parser)options = parser.parse_args()@@ -265,16 +269,50 @@ async def forward(upstream_port: int, request: web.Request) -> web.StreamResponsreturn response-app = web.Application()-app.add_routes(- [- web.route(- hdrs.METH_ANY, r"/{path:json/events|api/v1/events}", partial(forward, tornado_port)- ),- web.route(hdrs.METH_ANY, r"/{path:webpack/.*}", partial(forward, webpack_port)),- web.route(hdrs.METH_ANY, r"/{path:.*}", partial(forward, django_port)),- ]-)+async def help_center_middleware(+ request: web.Request, handler: Callable[[web.Request], Awaitable[web.StreamResponse]]+) -> web.StreamResponse:+ if request.path.startswith("/help-beta"):+ try:+ filename = request.match_info["filename"]+ name, ext = os.path.splitext(filename)+ if not ext:+ filename = os.path.join(filename, "index.html")+ request.match_info["filename"] = filename+ except KeyError:+ pass++ return await handler(request)+++middlewares = []+if options.help_center:+ middlewares.append(help_center_middleware)++app = web.Application(middlewares=middlewares)+++def setup_routes(enable_help_center: bool = False) -> None:+ if enable_help_center:+ # Order of adding the rules matters. aiohttp will stop at the first+ # match, and we want `/help-beta` to be matched before Django URIs.+ try:+ app.router.add_static("/help-beta", "help-beta/dist")+ except ValueError:+ print("""Please run the build step for the help center before enabling it.+The instructions for the build step can be found in the `./devtools`+page. `/help-beta` urls will give you an error until you complete the+build step and rerun `run-dev`.""")+ app.add_routes(+ [+ web.route(+ hdrs.METH_ANY, r"/{path:json/events|api/v1/events}", partial(forward, tornado_port)+ ),+ web.route(hdrs.METH_ANY, r"/{path:webpack/.*}", partial(forward, webpack_port)),+ web.route(hdrs.METH_ANY, r"/{path:.*}", partial(forward, django_port)),+ ]+ )def print_listeners() -> None:@@ -340,6 +378,8 @@ async def serve() -> None:else:children.append(start_webpack_watcher())+ setup_routes(options.help_center)+children.extend(subprocess.Popen(cmd) for cmd in server_processes())session = aiohttp.ClientSession()