Skip to content

Commit 2d390f3

Browse files
authored
feat: allow to customize api endpoint (#77)
* feat: allow to customize api endpoint * fix: regression Signed-off-by: Olivier Vernin <olivier@vernin.me> --------- Signed-off-by: Olivier Vernin <olivier@vernin.me>
1 parent f9c3757 commit 2d390f3

File tree

9 files changed

+30
-10
lines changed

9 files changed

+30
-10
lines changed

docker/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const config = (() => {
22
return {
33
"OAUTH_DOMAIN": "https://oauth.domain",
44
"OAUTH_CLIENTID": "client_id",
5-
"OAUTH_AUDIENCE": "http://localhost:8080/api"
5+
"OAUTH_AUDIENCE": "http://localhost:8080/api",
6+
"API_BASE_URL": "/api",
67
};
78
})();

src/components/pipeline/configs/_configsSearch.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888

8989
<script>
9090
91+
import { getApiBaseURL } from '@/composables/api';
92+
9193
export default {
9294
name: 'ConfigsSearchFilter',
9395
@@ -118,7 +120,7 @@ export default {
118120
this.$emit('loaded', false)
119121
const auth_enabled = process.env.VUE_APP_AUTH_ENABLED === 'true';
120122
121-
let query = `/api/pipeline/config/kinds?type=${this.configType}`;
123+
let query = `${getApiBaseURL()}/pipeline/config/kinds?type=${this.configType}`;
122124
123125
if (auth_enabled) {
124126
const token = await this.$auth0.getAccessTokenSilently();

src/components/pipeline/configs/config.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ import { toYAML } from '@/composables/yaml'
164164
import GitRepositorySection from './GitRepositorySection.vue'
165165
import ReportCard from './ReportCard.vue'
166166
167+
import { getApiBaseURL } from '@/composables/api';
168+
167169
export default {
168170
name: 'PipelineConfigView',
169171
components: {
@@ -383,7 +385,7 @@ export default {
383385
this.$emit('loaded', false)
384386
385387
try {
386-
const queryURL = `/api/pipeline/config/${this.configType}s/search`
388+
const queryURL = `${getApiBaseURL()}/pipeline/config/${this.configType}s/search`;
387389
const isAuthEnabled = process.env.VUE_APP_AUTH_ENABLED === 'true'
388390
389391
const jsonReqBody = { id: this.configID }
@@ -426,7 +428,7 @@ export default {
426428
427429
try {
428430
const isAuthEnabled = process.env.VUE_APP_AUTH_ENABLED === 'true'
429-
const queryURL = `/api/pipeline/reports/search`
431+
const queryURL = `${getApiBaseURL()}/pipeline/reports/search`
430432
431433
const jsonReqBody = {}
432434
const fieldMap = {

src/components/pipeline/configs/configs.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
<script>
195195
import { toYAML } from '@/composables/yaml'
196196
import { toLocalDate } from '@/composables/date'
197+
import { getApiBaseURL } from '@/composables/api';
197198
198199
export default {
199200
name: 'ConfigsTable',
@@ -302,7 +303,7 @@ export default {
302303
this.$emit('loaded', false);
303304
304305
try {
305-
let queryURL = `/api/pipeline/config/${this.resourceType}s/search`;
306+
let queryURL = `${getApiBaseURL()}/pipeline/config/${this.resourceType}s/search`;
306307
const isAuthEnabled = process.env.VUE_APP_AUTH_ENABLED === 'true';
307308
308309
// Build request body with pagination

src/components/pipeline/report.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ import PipelineGraphComponent from './_graph.vue';
240240
241241
import { getStatusColor, getStatusIcon, getStatusText } from '@/composables/status';
242242
import { toLocalDate } from '@/composables/date';
243+
import { getApiBaseURL } from '@/composables/api';
243244
244245
export default {
245246
name: 'PipelineReportView',
@@ -355,7 +356,7 @@ export default {
355356
const isAuthEnabled = process.env.VUE_APP_AUTH_ENABLED === 'true';
356357
if (isAuthEnabled) {
357358
const token = await this.$auth0.getAccessTokenSilently();
358-
const response = await fetch(`/api/pipeline/reports/` + this.$route.params.id, {
359+
const response = await fetch(`${getApiBaseURL()}/pipeline/reports/` + this.$route.params.id, {
359360
headers: {
360361
Authorization: `Bearer ${token}`
361362
}
@@ -370,7 +371,7 @@ export default {
370371
this.isLatestReport()
371372
}
372373
} else {
373-
const response = await fetch(`/api/pipeline/reports/` + this.$route.params.id);
374+
const response = await fetch(`${getApiBaseURL()}/pipeline/reports/` + this.$route.params.id);
374375
const data = await response.json();
375376
376377
this.pipeline = data.data;

src/components/pipeline/reports.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@
162162
import { getStatusColor, getStatusIcon } from '@/composables/status';
163163
import { extractGitURLInfo } from '@/composables/git'
164164
import { toLocalDate } from '@/composables/date'
165+
import { getApiBaseURL } from '@/composables/api';
165166
166167
export default {
167168
name: 'PipelinesTable',
@@ -279,7 +280,7 @@ export default {
279280
280281
async getReportsData(page =1 ) {
281282
this.$emit('loaded', false)
282-
let queryURL = `/api/pipeline/reports`
283+
let queryURL = `${getApiBaseURL()}/pipeline/reports`
283284
284285
const params = new URLSearchParams();
285286
if (this.scmid != undefined && this.scmid != '' && this.scmid != null) {

src/components/scm/_filter.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
<script>
5959
import router from '../../router'
6060
61+
import { getApiBaseURL } from '@/composables/api';
62+
6163
export default {
6264
name: 'PipelineSCMS',
6365
@@ -90,7 +92,7 @@ export default {
9092
this.$emit('loaded', false)
9193
const auth_enabled = process.env.VUE_APP_AUTH_ENABLED === 'true';
9294
93-
let query = `/api/pipeline/scms`;
95+
let query = `${getApiBaseURL()}/pipeline/scms`;
9496
9597
if (this.restrictedSCM != "") {
9698
query = query + `?scmid=${this.restrictedSCM}`

src/components/scm/_summary.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ import router from '../../router'
195195
196196
import SCMDoughnut from './_scmDoughnut.vue'
197197
198+
import { getApiBaseURL } from '@/composables/api';
199+
198200
ChartJS.register(RadialLinearScale, ArcElement, Tooltip, Legend)
199201
200202
export default {
@@ -334,7 +336,7 @@ export default {
334336
params.append('scmid', this.scmid);
335337
}
336338
337-
let query = `/api/pipeline/scms?${params.toString()}`;
339+
let query = `${getApiBaseURL()}/pipeline/scms?${params.toString()}`;
338340
339341
let response;
340342
if (auth_enabled) {

src/composables/api.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
// getApiBaseURL returns the base URL for API requests with no trailing slash
3+
export function getApiBaseURL() {
4+
const raw = config.API_BASE_URL || '/api'
5+
6+
// remove any trailing slashes so we can safely append paths like "/pipeline/..."
7+
return raw.replace(/\/+$/, '')
8+
}

0 commit comments

Comments
 (0)