Skip to content

Commit b1298a8

Browse files
authored
Merge pull request #801 from Squixx/feat/urlpath
Feature: add support for serving from custom path
2 parents 0ebd445 + 7fb7223 commit b1298a8

File tree

8 files changed

+37
-19
lines changed

8 files changed

+37
-19
lines changed

.dockerignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ docs/
1010
node_modules/
1111
release.sh
1212
snapshot.sh
13-
!docker/etc/nginx/conf.d/default.conf
13+
!docker/etc/nginx/templates/default.conf.template
1414
!docker/docker-entrypoint.d/*.sh

docker/Dockerfile.alpine

+7-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ ENV TZ=Etc/UTC \
99
LANG=C.UTF-8 \
1010
# Set default settings that may get overridden to empty values by
1111
# the entrypoint script, if not explicitly provided by the user
12-
OIDC_SCOPE="openid profile email"
13-
12+
OIDC_SCOPE="openid profile email" \
13+
BASE_PATH="/"
1414
USER root
1515

1616
# Copy the static HTML and JS files to the application directory
@@ -29,10 +29,13 @@ RUN chown -R 101:0 ${APP_DIR} \
2929
# See https://github.com/nginxinc/docker-nginx-unprivileged/blob/main/stable/alpine/Dockerfile#L139
3030
USER 101
3131

32+
RUN mkdir /etc/nginx/templates
3233
# Setup entrypoint
33-
COPY --chown=101:0 ./docker/etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
34+
COPY --chown=101:0 ./docker/etc/nginx/templates/default.conf.template /etc/nginx/templates/default.conf.template
35+
3436
COPY --chmod=755 ./docker/docker-entrypoint.d/ /docker-entrypoint.d/
3537

38+
3639
# Specify the container working directory
3740
WORKDIR ${APP_DIR}
3841

@@ -46,4 +49,4 @@ LABEL \
4649
org.opencontainers.image.source="https://github.com/DependencyTrack/frontend" \
4750
org.opencontainers.image.revision="${COMMIT_SHA}" \
4851
org.opencontainers.image.licenses="Apache-2.0" \
49-
maintainer="[email protected]"
52+
maintainer="[email protected]"

docker/docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ services:
1818
- dtrack-apiserver
1919
environment:
2020
- "API_BASE_URL=http://localhost:8081"
21+
# - "BASE_PATH=/"
2122
# - "OIDC_ISSUER="
2223
# - "OIDC_CLIENT_ID="
2324
# - "OIDC_SCOPE="

docker/etc/nginx/conf.d/default.conf docker/etc/nginx/templates/default.conf.template

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ server {
66
root /opt/owasp/dependency-track-frontend;
77
index index.html;
88
try_files $uri $uri/ /index.html;
9+
10+
sub_filter '<base href=/' '<base href=${BASE_PATH}';
11+
sub_filter_once on;
912
}
1013

1114
error_page 500 502 503 504 /50x.html;
1215

1316
location = /50x.html {
1417
root /usr/share/nginx/html;
1518
}
16-
}
19+
}

public/index.html

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
4-
<meta charset="utf-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<meta name="viewport" content="width=device-width,initial-scale=1.0">
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
77
<title>Dependency-Track</title>
8+
<base href="/" />
89
</head>
910
<body class="sidebar-minimized">
1011
<noscript>
11-
<strong>We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
12+
<strong
13+
>We're sorry but this app doesn't work properly without JavaScript
14+
enabled. Please enable it to continue.</strong
15+
>
1216
</noscript>
1317
<div id="app"></div>
1418
<script type="text/javascript">
15-
(function() {
19+
(function () {
1620
if (!sessionStorage.length) {
1721
// Ask other tabs for session storage
1822
localStorage.setItem('getSessionStorage', Date.now());
19-
};
23+
}
2024
window.addEventListener('storage', function (event) {
2125
if (event.key == 'getSessionStorage') {
2226
// Some tab asked for the sessionStorage -> send it
23-
localStorage.setItem('sessionStorage', JSON.stringify(sessionStorage));
27+
localStorage.setItem(
28+
'sessionStorage',
29+
JSON.stringify(sessionStorage),
30+
);
2431
localStorage.removeItem('sessionStorage');
2532
} else if (event.key == 'sessionStorage' && !sessionStorage.length) {
2633
// sessionStorage is empty -> fill it
27-
var data = JSON.parse(event.newValue), value;
34+
var data = JSON.parse(event.newValue),
35+
value;
2836
for (key in data) {
2937
sessionStorage.setItem(key, data[key]);
3038
}

public/static/oidc-callback.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
}
3434
}
3535

36-
axios.get("/static/config.json")
36+
axios.get("./config.json")
3737
.then((response) => {
3838
let config = response.data;
3939

src/views/pages/Login.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ import { ValidationObserver } from 'vee-validate';
103103
import BValidatedInputGroupFormInput from '../../forms/BValidatedInputGroupFormInput';
104104
import InformationalModal from '../modals/InformationalModal';
105105
import EventBus from '../../shared/eventbus';
106-
import { getRedirectUrl } from '../../shared/utils';
106+
import { getRedirectUrl, getContextPath } from '../../shared/utils';
107107
const qs = require('querystring');
108108
109109
export default {
@@ -125,7 +125,10 @@ export default {
125125
userStore: new Oidc.WebStorageStateStore(),
126126
authority: this.$oidc.ISSUER,
127127
client_id: this.$oidc.CLIENT_ID,
128-
redirect_uri: `${window.location.origin}/static/oidc-callback.html`,
128+
redirect_uri:
129+
getContextPath() !== ''
130+
? `${window.location.origin}${getContextPath()}/static/oidc-callback.html`
131+
: `${window.location.origin}/static/oidc-callback.html`,
129132
response_type:
130133
this.$oidc.FLOW === 'implicit' ? 'token id_token' : 'code',
131134
scope: this.$oidc.SCOPE,

vue.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = {
55
productionSourceMap: false,
66
runtimeCompiler: true,
77
// Relative paths cannot be supported. Research by @nscur0 - https://owasp.slack.com/archives/CTC03GX9S/p1608400149085400
8-
publicPath: '/',
8+
publicPath: '.',
99
devServer: {
1010
proxy: { '/api': { target: process.env.VUE_APP_SERVER_URL } },
1111
},

0 commit comments

Comments
 (0)