Commit 6b82d022 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

serve static files under /webui/, allows nuxt client to override base path with env var BASE_PATH

parent b12bbbbb
......@@ -99,6 +99,11 @@ export default {
},
},
// https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-router#base
router: {
base: process.env.BASE_PATH || '/',
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
}
......
......@@ -76,6 +76,14 @@ def absolute_path_of_the_file(fileName, output_file=False):
def serve(args):
if not os.path.exists('client/dist'):
print("Application cannot be served unless you build the client.")
print("To do so, please run :")
print(" cd client")
print(" yarn install")
print(" export BASE_PATH='/webui/'")
print(" yarn generate")
exit(1)
uvicorn.run(app='jass.server:app', host=config["HOST"], port=int(config["PORT"]))
......
#!/usr/bin/env python3
import logging
import os
from pathlib import Path
from typing import List
from starlette.responses import RedirectResponse
from jass import util
from jass.config import config
from jass.models.phenotype import Phenotype, get_available_phenotypes, PhenotypeIdList
from jass.models.inittable import get_inittable_meta
......@@ -23,6 +26,13 @@ app.add_middleware(
allow_headers=["*"],
)
app.mount("/webui", util.SinglePageApplication(directory=Path('client/dist')), name="SPA")
@app.get("/")
async def read_index():
return RedirectResponse(url="/webui/")
@app.get("/api/phenotypes", response_model=List[Phenotype])
def phenotypes_list():
......
import datetime
import importlib
import os
import pickle
import six
from starlette.staticfiles import StaticFiles
from typing import Tuple
try:
import typing
except ImportError:
......@@ -163,4 +167,34 @@ class PickleProtocol:
def coerce_pickle_protocol(level):
return PickleProtocol(level)
\ No newline at end of file
return PickleProtocol(level)
class SinglePageApplication(StaticFiles):
"""
https://stackoverflow.com/a/68843198/2144569
"""
def __init__(self, directory: os.PathLike, index='index.html') -> None:
self.index = index
# set html=True to resolve the index even when no
# the base path is passed in
super().__init__(directory=directory, packages=None, html=True, check_dir=True)
def lookup_path(self, path: str) -> Tuple[str, os.stat_result]:
"""Returns the index file when no match is found.
Args:
path (str): Resource path.
Returns:
[tuple[str, os.stat_result]]: Always returns a full path and stat result.
"""
full_path, stat_result = super().lookup_path(path)
# if a file cannot be found
if stat_result is None:
return super().lookup_path(self.index)
return full_path, stat_result
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment