Skip to content

Commit ab304c1

Browse files
committed
Add server functionality for port forwarding
- This PR implements additional server functionality for the webviewer, enabling local visualizations even though the webviewer is run on a remote machine. - Specifically, the user can specify whether the webviewer should be run in server mode, and on which port, thereby enabling SSH port forwarding.
1 parent 6c5a483 commit ab304c1

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ pre-commit install
5151

5252
## Using the 4C-Webviewer
5353

54-
To start the webviewer, in the conda environment run:
54+
After activating the conda environment, start the webviewer by using:
5555
```
5656
fourc_webviewer
5757
```
58+
5859
To directly open a YAML input file use
5960
```
6061
fourc_webviewer --fourc_yaml_file <path-to-4C-YAML-input-file>
@@ -65,6 +66,20 @@ Alternatively change to the directory of the repo. Activate the created conda en
6566
python main.py
6667
```
6768

69+
The webviewer can also be run in server mode on a remote machine without opening the browser:
70+
```
71+
fourc_webviewer --fourc_yaml_file <path-to-4C-YAML-input-file> --server --port 12345
72+
```
73+
Then, on your local machine, forward the bound port 12345:
74+
```
75+
ssh -N -L 12345:localhost:12345 user@remote
76+
```
77+
and open the local browser at:
78+
```
79+
http://localhost:12345
80+
```
81+
82+
6883
## Dependency Management
6984

7085
To ease the dependency update process [`pip-tools`](https://github.com/jazzband/pip-tools) is utilized. To create the necessary [`requirements.txt`](./requirements.txt) file simply execute

src/fourc_webviewer/cli_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ def get_arguments():
2121
parser.add_argument(
2222
"--fourc_yaml_file", type=str, help="input file path to visualize"
2323
)
24+
parser.add_argument(
25+
"--server",
26+
action="store_true",
27+
help="start app in server mode without opening the browser? (useful for local port forwarding via ssh)",
28+
)
29+
parser.add_argument(
30+
"--port",
31+
type=int,
32+
help="port to start the app on",
33+
)
2434

2535
args = parser.parse_args()
2636

src/fourc_webviewer/run_webserver.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from fourc_webviewer.fourc_webserver import FourCWebServer
44
from fourc_webviewer_default_files import DEFAULT_INPUT_FILE
55

6-
# specify server port for the app to run on
7-
SERVER_PORT = 12345
6+
# specify default port for running the app
7+
DEFAULT_PORT = 12345
88

99

10-
def run_webviewer(fourc_yaml_file=None):
10+
def run_webviewer(fourc_yaml_file=None, port=None, server=None):
1111
"""Runs the webviewer by creating a dedicated webserver object, starting it
1212
and cleaning up afterwards."""
1313

@@ -18,7 +18,9 @@ def run_webviewer(fourc_yaml_file=None):
1818
fourc_webserver = FourCWebServer(fourc_yaml_file)
1919

2020
# start the server after everything is set up
21-
fourc_webserver.server.start(port=SERVER_PORT)
21+
server_port = port or DEFAULT_PORT
22+
open_browser = not server
23+
fourc_webserver.server.start(port=server_port, open_browser=open_browser)
2224

2325
# run cleanup
2426
fourc_webserver.cleanup()

0 commit comments

Comments
 (0)