From 6cf4fa73f5067a58cda54ae613097623c3af5d1e Mon Sep 17 00:00:00 2001 From: Emilio Righi Date: Fri, 2 Aug 2024 18:48:41 +0200 Subject: [PATCH] add subpath logic --- biogenome-client/Dockerfile | 18 +++++++--- .../{default.conf.template => root.template} | 0 biogenome-client/select-template.sh | 12 +++++++ .../components/genome-browser/Jbrowse2.vue | 10 +++--- biogenome-client/src/http-axios.js | 6 ++-- biogenome-client/src/router/index.ts | 6 +--- biogenome-client/subpath.template | 34 +++++++++++++++++++ biogenome-client/vite.config.ts | 5 +-- 8 files changed, 71 insertions(+), 20 deletions(-) rename biogenome-client/{default.conf.template => root.template} (100%) create mode 100644 biogenome-client/select-template.sh create mode 100644 biogenome-client/subpath.template diff --git a/biogenome-client/Dockerfile b/biogenome-client/Dockerfile index ca3b22b7..9b3a0329 100644 --- a/biogenome-client/Dockerfile +++ b/biogenome-client/Dockerfile @@ -2,8 +2,6 @@ FROM node:17 as build-stage ARG ROOT_NODE -ARG PROJECT_ACCESSION - ARG CESIUM_TOKEN ARG BASE_PATH @@ -19,7 +17,6 @@ COPY . . COPY ./ducd node_modules/ducd ENV VITE_ROOT_NODE=${ROOT_NODE} -ENV VITE_PROJECT_ACCESSION=${PROJECT_ACCESSION} ENV VITE_CESIUM_TOKEN=${CESIUM_TOKEN} ENV VITE_BASE_PATH=${BASE_PATH} @@ -29,8 +26,19 @@ RUN npm run build # production stage FROM nginx:stable-alpine -# copy the nginx.conf in our filesystem into the image filesystem -COPY default.conf.template /etc/nginx/templates/default.conf.template +ARG BASE_PATH + +# Copy the nginx templates +COPY root.template /etc/nginx/templates/root.template +COPY subpath.template /etc/nginx/templates/subpath.template + +# Copy the script +COPY select-template.sh /usr/local/bin/select-template.sh + +RUN chmod +x /usr/local/bin/select-template.sh + +# Set the config file based on the build argument +RUN /usr/local/bin/select-template.sh COPY --from=build-stage /client/dist /usr/share/nginx/html diff --git a/biogenome-client/default.conf.template b/biogenome-client/root.template similarity index 100% rename from biogenome-client/default.conf.template rename to biogenome-client/root.template diff --git a/biogenome-client/select-template.sh b/biogenome-client/select-template.sh new file mode 100644 index 00000000..b3ca1e39 --- /dev/null +++ b/biogenome-client/select-template.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# Print the value of BASE_PATH for debugging +echo "BASE_PATH is: $BASE_PATH" + +if [ -z "$BASE_PATH" ]; then + echo "BASE_PATH is empty or not set. Using root.template." + cp /etc/nginx/templates/root.template /etc/nginx/templates/default.conf.template +else + echo "BASE_PATH is set to: $BASE_PATH. Using subpath.template." + cp /etc/nginx/templates/subpath.template /etc/nginx/templates/default.conf.template +fi diff --git a/biogenome-client/src/components/genome-browser/Jbrowse2.vue b/biogenome-client/src/components/genome-browser/Jbrowse2.vue index bc5def9f..f0c0b794 100644 --- a/biogenome-client/src/components/genome-browser/Jbrowse2.vue +++ b/biogenome-client/src/components/genome-browser/Jbrowse2.vue @@ -11,7 +11,7 @@ import RefGetPlugin from 'jbrowse-plugin-refget-api' import { Assembly, AssemblyAdapter, TrackData } from '../../data/types' // import '@fontsource/roboto' const wrapper = ref(null) -const baseURL = import.meta.env.VITE_BASE_PATH? import.meta.env.VITE_BASE_PATH + 'api' : '/api' +const baseURL = import.meta.env.VITE_BASE_PATH ? import.meta.env.VITE_BASE_PATH + '/api' : '/api' const props = defineProps<{ defaultSession?: Record configuration?: Record @@ -52,13 +52,13 @@ function parseAssembly(assembly: Assembly) { }, }, } - if(assembly.has_chromosomes_aliases){ + if (assembly.has_chromosomes_aliases) { assemblyAdapter.refNameAliases = { - adapter : { + adapter: { type: "RefNameAliasAdapter", location: { - uri:`${baseURL}/assemblies/${assembly.accession}/chr_aliases`, - locationType:"UriLocation" + uri: `${baseURL}/assemblies/${assembly.accession}/chr_aliases`, + locationType: "UriLocation" } } } diff --git a/biogenome-client/src/http-axios.js b/biogenome-client/src/http-axios.js index 02eea0f9..572115df 100644 --- a/biogenome-client/src/http-axios.js +++ b/biogenome-client/src/http-axios.js @@ -1,6 +1,6 @@ import axios from 'axios' -const baseURL = import.meta.env.VITE_BASE_PATH? import.meta.env.VITE_BASE_PATH + 'api' : '/api' +const baseURL = import.meta.env.VITE_BASE_PATH ? import.meta.env.VITE_BASE_PATH + '/api' : '/api' const base = axios.create({ baseURL: baseURL, headers: { @@ -8,7 +8,7 @@ const base = axios.create({ }, }) -const download = axios.create({ +const download = axios.create({ baseURL: baseURL, responseType: 'blob' }) @@ -47,5 +47,5 @@ export default { base: base, ena: ena, ncbi: ncbi, - download:download + download: download } diff --git a/biogenome-client/src/router/index.ts b/biogenome-client/src/router/index.ts index 6f330152..11b641f1 100644 --- a/biogenome-client/src/router/index.ts +++ b/biogenome-client/src/router/index.ts @@ -4,10 +4,6 @@ import { models, maps, cms } from '../../config.json' import { cmsRoutes } from './cms-routes' import { modelRoutes, mapRoutes } from './custom-routes' -const rootNode = import.meta.env.VITE_ROOT_NODE ? - import.meta.env.VITE_ROOT_NODE : '131567' - - const defaultRoutes: Array = [ { path: '/:catchAll(.*)', @@ -76,7 +72,7 @@ function createRoutes() { const routes = [...createRoutes()] const router = createRouter({ - history: createWebHistory(import.meta.env.BASE_URL), + history: createWebHistory(import.meta.env.VITE_BASE_PATH ? import.meta.env.VITE_BASE_PATH : import.meta.env.BASE_URL), routes, }) diff --git a/biogenome-client/subpath.template b/biogenome-client/subpath.template new file mode 100644 index 00000000..c85e0efa --- /dev/null +++ b/biogenome-client/subpath.template @@ -0,0 +1,34 @@ +proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m; + +server { + + root /usr/share/nginx/html; + + listen ${API_PORT}; + location ${BASE_PATH} { + rewrite ${BASE_PATH}/(.*) /$1 break; + try_files $uri $uri/ /index.html; + client_max_body_size 1000M; + } + + location ${BASE_PATH}/files/ { + rewrite ${BASE_PATH}/(.*) /$1 break; + alias /var/www/statics/; + } + + location ${BASE_PATH}/api { + rewrite ${BASE_PATH}/(.*) /$1 break; + + # Define cache parameters + proxy_cache my_cache; + proxy_cache_valid 200 10m; + proxy_cache_methods GET HEAD; + proxy_cache_key $scheme$proxy_host$request_uri; + + + include uwsgi_params; + uwsgi_pass ${API_HOST}:${API_PORT}; + client_max_body_size 1000M; + uwsgi_read_timeout 600; + } +} diff --git a/biogenome-client/vite.config.ts b/biogenome-client/vite.config.ts index 812a10c1..1d2ad398 100644 --- a/biogenome-client/vite.config.ts +++ b/biogenome-client/vite.config.ts @@ -11,9 +11,10 @@ export default ({ mode }) => { // import.meta.env.VITE_NAME available here with: process.env.VITE_NAME // import.meta.env.VITE_PORT available here with: process.env.VITE_PORT - + const basePath = env.VITE_BASE_PATH ? env.VITE_BASE_PATH + '/': undefined + console.log(basePath) return defineConfig({ - base: env.VITE_BASE_PATH ? env.VITE_BASE_PATH : '/', + base: basePath, resolve: { alias: { stream: 'stream-browserify',