Skip to content

Commit f39a6c0

Browse files
committed
Added parameters and logic to resolve original proxy path for use in documentation if HTTP request was passed to server via frontend
1 parent 03a2b40 commit f39a6c0

File tree

4 files changed

+61
-26
lines changed

4 files changed

+61
-26
lines changed

src/murfey/server/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ def respond_with_template(
216216
"hostname": get_hostname(),
217217
"microscope": get_microscope(),
218218
"version": murfey.__version__,
219+
# Extra parameters to reconstruct URLs for forwarded requests
220+
"netloc": request.url.netloc,
221+
"proxy_path": "",
219222
}
220223
if parameters:
221224
template_parameters.update(parameters)

src/murfey/server/api/bootstrap.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,23 @@ def get_bootstrap_instructions(request: Request):
105105
machine with no internet access.
106106
"""
107107

108+
# Constructs the netloc (hostname + port) and proxy path depending on if the
109+
# request was forwarded via proxy
110+
netloc = (
111+
f"{request.headers['X-Forwarded-Host']}:{request.headers['X-Forwarded-Port']}"
112+
if request.headers.get("X-Forwarded-Host")
113+
and request.headers.get("X-Forwarded-Port")
114+
else request.url.netloc
115+
)
116+
# Additional bit in URL path after the netloc caused by the proxy reroute
117+
proxy_path = request.url.path.removesuffix(f"{bootstrap.prefix}/")
118+
108119
return respond_with_template(
109120
request=request,
121+
parameters={
122+
"netloc": netloc,
123+
"proxy_path": proxy_path,
124+
},
110125
filename="bootstrap.html",
111126
)
112127

src/murfey/templates/base.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<html>
22
<head>
33
<title>Murfey - {% block title %}{% endblock %}</title>
4-
<link href="{{ url_for('static', path='/styles.css') }}" rel="stylesheet" />
54
<link
6-
href="{{ url_for('images', path='/icon_268.png') }}"
5+
href="{{ proxy_path }}{{ url_for('static', path='/styles.css') }}"
6+
rel="stylesheet"
7+
/>
8+
<link
9+
href="{{ proxy_path }}{{ url_for('images', path='/icon_268.png') }}"
710
rel="icon"
811
type="image/png"
912
/>
1013
</head>
1114
<body>
1215
<div class="topnav">
13-
<a href="/">Home</a>
14-
<a href="/visits">Active Visits</a>
15-
<a href="/bootstrap">Installation instructions</a>
16-
<a href="/pypi/fastapi">FastAPI PyPI</a>
16+
<a href="{{ proxy_path }}/docs">Home</a>
17+
<a href="{{ proxy_path }}/bootstrap">Installation Instructions</a>
18+
<a href="{{ proxy_path }}/pypi/fastapi">FastAPI (PyPI)</a>
1719
<p style="text-align: right; margin: 8px 10px 0 auto">
1820
<img
19-
src="{{ url_for('images', path='/diamond.png') }}"
21+
src="{{ proxy_path }}{{ url_for('images', path='/diamond.png') }}"
2022
style="height: 25px"
2123
/>
2224
</p>
Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
11
{% extends "base.html" %} {% block title %}Bootstrapping instructions{% endblock
22
%} {% block content %}
33
<h1>Bootstrapping instructions</h1>
4-
<h2>Installing a Linux Terminal</h2>
4+
<h2>Installing a Linux Environment</h2>
55
<h3>Installing Cygwin</h3>
66
<p>
7-
If you already have a Cygwin install, rename it so that it doesn't get
8-
overwritten (something like "[install name]-old").
7+
If you already have a Cygwin install that you would like to preserve, rename
8+
it so that it doesn't get overwritten (something like "cygwin64-old").
99
</p>
1010
<p>
1111
Download the Cygwin setup executable using this
12-
<a href="/cygwin/setup-x86_64.exe">mirror</a>, and then run the following from
13-
a terminal (both Command Prompt and Windows Powershell work)
12+
<a href="{{ proxy_path }}/cygwin/setup-x86_64.exe">mirror</a>, and then run
13+
the following from a terminal (both Command Prompt and Windows Powershell
14+
work)
1415
</p>
1516
<pre style="font-family: monospace">
16-
$ setup-x86_64.exe -O -R C:\cygwin64 -s {{ request.url.scheme }}://{{ request.url.netloc }}/cygwin -P curl,python3,rsync -q
17+
$ setup-x86_64.exe -O -R C:\cygwin64 -s {{ request.url.scheme }}://{{ netloc }}{{ proxy_path }}/cygwin -P curl,python3,rsync -q
1718
</pre>
1819
<p>
19-
The Cygwin install sometimes hangs even when it is finished, hit Enter to
20-
return to a command prompt.
20+
This will install Cygwin with the minimum packages needed to run Murfey. The
21+
Cygwin install command will occasionally hang after completion. In such an
22+
event, just hit Enter to return to a normal command prompt window.
2123
</p>
2224

2325
<h3>Installing MSYS2</h3>
2426
<p>
2527
MSYS2 is a lightweight Linux environment which provides compiler support for
26-
the more modern programming languages used in the backend of Murfey's package
27-
dependencies.
28+
the more modern programming languages used by Murfey's package dependencies.
2829
</p>
2930
<p>
3031
The Murfey server supports the forwarding of download requests to client PCs
3132
that cannot access the wider internet. Download the MSYS2 setup executable
32-
using this <a href="/msys2/setup-x86_64.exe">mirror</a>, and run the
33-
executable using the default settings.
33+
using this
34+
<a href="{{ proxy_path }}/msys2/distrib/msys2-x86_64-latest.exe">mirror</a>,
35+
and run the executable using the default settings. This will install it to
36+
C:\msys64.
3437
</p>
3538
<p>
3639
By default, MSYS2 comes with preset lists of mirrors and servers that it
@@ -48,7 +51,7 @@ <h3>Installing MSYS2</h3>
4851
<p>This is an example of how the URL to the Murfey server should look like:</p>
4952
<pre style="font-family: monospace">
5053
Server = https://repo.msys2.org/mingw/x86_64/ # Original URL
51-
Server = {{ request.url.scheme }}://{{ request.url.netloc }}/msys2/mingw/x86_64 # Murfey URL
54+
Server = {{ request.url.scheme }}://{{ netloc }}{{ proxy_path }}/msys2/mingw/x86_64/ # Murfey URL
5255
</pre>
5356
<p>
5457
MSYS2 comes with multiple environments, but UCRT64 is the most modern one. In
@@ -57,11 +60,20 @@ <h3>Installing MSYS2</h3>
5760
environment. This can be achieved using the following commands:
5861
</p>
5962
<pre style="font-family: monospace">
60-
$ pacman -Syu --disable-download-timeout # Downloads the package database and searches for updates
61-
$ pacman -S rsync --disable-download-timeout
62-
$ pacman -S mingw-w64-python-pip --disable-download-timeout
63-
$ pacman -S mingw-w64-x86_64-rust --disable-download-timeout
63+
$ pacman -Syu
64+
$ pacman -S rsync
65+
$ pacman -S mingw-w64-ucrt-x86_64-python-pip
66+
$ pacman -S mingw-w64-ucrt-x86_64-rust
6467
</pre>
68+
<p>
69+
Other utility packages such as
70+
<span style="font-family: monospace">vim</span> can also be installed by
71+
running
72+
<span style="font-family: monospace">pacman -S &lt;package-name&gt;</span>.
73+
You can browse the other packages supported by
74+
<span style="font-family: monospace">pacman</span> by searching the repo using
75+
<span style="font-family: monospace">pacman -Ss &lt;package-name&gt;</span>
76+
</p>
6577

6678
<h2>Setting Up Python</h2>
6779
<p>
@@ -73,7 +85,7 @@ <h2>Setting Up Python</h2>
7385
<h3>Setting Up a Virtual Environment</h3>
7486
<p>To set up a virtual environment, run the following commands:</p>
7587
<pre style="font-family: monospace">
76-
$ pip install virtualenv --index-url {{ request.url.scheme }}://{{ request.url.netloc }}/pypi --trusted-host {{ request.url.hostname }}
88+
$ pip install virtualenv --index-url {{ request.url.scheme }}://{{ netloc }}{{ proxy_path }}/pypi --trusted-host {{ netloc }}
7789
$ virtualenv your-env-name # Create the virtual environment
7890
$ source your-env-name/bin/activate # Activate the virtual environment
7991
</pre>
@@ -84,6 +96,9 @@ <h3>Installing Murfey</h3>
8496
commands:
8597
</p>
8698
<pre style="font-family: monospace">
87-
$ pip install murfey[client] --index-url {{ request.url.scheme }}://{{ request.url.netloc }}/pypi --trusted-host {{ request.url.hostname }}
99+
$ pip install murfey[client] --index-url {{ request.url.scheme }}://{{ netloc }}{{ proxy_path }}/pypi --trusted-host {{ netloc }}
100+
</pre>
101+
<pre>
102+
If you wish to install the client-side dependencies needed to run Murfey via the web UI, replace <span style="font-family: monospace;">murfey[client]</span> with <span style="font-family: monospace;">murfey[client,instrument-server]</span>.
88103
</pre>
89104
{% endblock %}

0 commit comments

Comments
 (0)