Skip to content

Commit

Permalink
fix: properly setup vite build & backend server (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Sep 1, 2023
1 parent 644a2d4 commit 96d4151
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
14 changes: 9 additions & 5 deletions backend/app/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pathlib
import sys

import httpx
Expand All @@ -8,7 +9,7 @@
from fastapi.staticfiles import StaticFiles
from starlette.background import BackgroundTask
from starlette.requests import Request
from starlette.responses import RedirectResponse, Response, StreamingResponse
from starlette.responses import FileResponse, RedirectResponse, Response, StreamingResponse

# Load environment
env = os.environ
Expand Down Expand Up @@ -80,13 +81,16 @@ async def reverse_proxy(request: Request) -> Response:
# Register reverse proxy route
app.add_route("/proxy/{path:path}", reverse_proxy, methods=["GET", "POST"])

# Register route for favicon.
@app.get("/favicon.ico")
async def favicon():
return FileResponse(pathlib.Path(__file__).parent.parent.parent / "frontend/public/favicon.ico")

# Routes
if SERVE_FRONTEND: # pragma: no cover
print(f"SERVE_FRONTEND = {SERVE_FRONTEND}", file=sys.stderr)
app.mount("/ui", StaticFiles(directory=SERVE_FRONTEND), name="app")
app.mount("/assets", StaticFiles(directory=f"{SERVE_FRONTEND}/assets"), name="ui")

@app.get("/")
async def redirect():
response = RedirectResponse(url="/ui/index.html")
return response
async def index():
return FileResponse(f"{SERVE_FRONTEND}/index.html")
10 changes: 5 additions & 5 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
<title>Loading REEV...</title>
</head>
<body>
<div id="app"></div>
Expand All @@ -22,22 +22,22 @@
min-height: 100vh; /* Ensure the content takes up at least the full viewport height */
font-weight: normal;
}

a,
.green {
text-decoration: none;
color: rgb(111, 100, 210);
transition: 0.4s;
}

@media (min-width: 1024px) {
body {
display: flex;
justify-content: center; /* Center horizontally */
align-items: center; /* Center vertically */
min-height: 100vh; /* Ensure the body takes up at least the full viewport height */
}

#app {
display: grid;
grid-template-columns: 1fr;
Expand All @@ -46,4 +46,4 @@
align-items: center; /* Center horizontally */
}
}
</style>
</style>
Binary file modified frontend/public/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion frontend/src/api/annonars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class AnnonarsClient {
}

async fetchGeneInfo(hgncId: string): Promise<any> {
const response = await fetch(`${this.apiBaseUrl}genes/info?hgnc-id=${hgncId}`, {
const response = await fetch(`${this.apiBaseUrl}genes/info?hgnc_id=${hgncId}`, {
method: 'GET'
})
return await response.json()
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { nextTick } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'

import HomeView from '@/views/HomeView.vue'
Expand Down Expand Up @@ -37,6 +38,17 @@ const router = createRouter({
routes
})

/** The default page title */
const DEFAULT_TITLE = 'REEV Explains and Evaluates Variants'

router.afterEach((to, _from) => {

Check warning on line 44 in frontend/src/router/index.ts

View workflow job for this annotation

GitHub Actions / Frontend-Lint

'_from' is defined but never used
// Use next tick to handle router history correctly
// see: https://github.com/vuejs/vue-router/issues/914#issuecomment-384477609
nextTick(() => {
document.title = to.meta.title as string ?? DEFAULT_TITLE
})
});

export { routes }

export default router
6 changes: 4 additions & 2 deletions frontend/src/views/GeneDetailView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ const geneInfoStore = useGeneInfoStore()
const scrollToSection = async () => {
const sectionId = route.hash.slice(1)
const elem = document.getElementById(sectionId)
elem?.scrollIntoView()
if (sectionId) {
const elem = document.getElementById(sectionId)
elem?.scrollIntoView()
}
}
const loadDataToStore = async () => {
Expand Down
1 change: 0 additions & 1 deletion frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default defineConfig({
vueJsx(),
vuetify()
],
base: './',
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
Expand Down

0 comments on commit 96d4151

Please sign in to comment.