Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly setup vite build & backend server (#21) #22

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 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 @@ -81,12 +82,17 @@
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")

Check warning on line 88 in backend/app/main.py

View check run for this annotation

Codecov / codecov/patch

backend/app/main.py#L88

Added line #L88 was not covered by tests


# 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 @@
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(() => {

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

View check run for this annotation

Codecov / codecov/patch

frontend/src/router/index.ts#L47

Added line #L47 was not covered by tests
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 scrollToSection = async () => {
const sectionId = route.hash.slice(1)
const elem = document.getElementById(sectionId)
elem?.scrollIntoView()
if (sectionId) {
const elem = document.getElementById(sectionId)
elem?.scrollIntoView()

Check warning on line 27 in frontend/src/views/GeneDetailView.vue

View check run for this annotation

Codecov / codecov/patch

frontend/src/views/GeneDetailView.vue#L26-L27

Added lines #L26 - L27 were not covered by tests
}
}

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
Loading