Skip to content

Commit

Permalink
add subpath logic
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliorighi committed Aug 2, 2024
1 parent 9c92d92 commit 6cf4fa7
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 20 deletions.
18 changes: 13 additions & 5 deletions biogenome-client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ FROM node:17 as build-stage

ARG ROOT_NODE

ARG PROJECT_ACCESSION

ARG CESIUM_TOKEN

ARG BASE_PATH
Expand All @@ -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}

Expand All @@ -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

Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions biogenome-client/select-template.sh
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions biogenome-client/src/components/genome-browser/Jbrowse2.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>
configuration?: Record<string, any>
Expand Down Expand Up @@ -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"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions biogenome-client/src/http-axios.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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: {
'Content-type': 'application/json',
},
})

const download = axios.create({
const download = axios.create({
baseURL: baseURL,
responseType: 'blob'
})
Expand Down Expand Up @@ -47,5 +47,5 @@ export default {
base: base,
ena: ena,
ncbi: ncbi,
download:download
download: download
}
6 changes: 1 addition & 5 deletions biogenome-client/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RouteRecordRaw> = [
{
path: '/:catchAll(.*)',
Expand Down Expand Up @@ -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,
})

Expand Down
34 changes: 34 additions & 0 deletions biogenome-client/subpath.template
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 3 additions & 2 deletions biogenome-client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 6cf4fa7

Please sign in to comment.