diff --git a/front/src/api/index.js b/front/src/api/index.js index 1d7949e9..ba15ada6 100644 --- a/front/src/api/index.js +++ b/front/src/api/index.js @@ -1,6 +1,7 @@ import axios from "axios"; +import { SCRIPT_NAME } from '../scriptname.js'; -axios.defaults.baseURL = "/api"; +axios.defaults.baseURL = SCRIPT_NAME + '/api' axios.defaults.xsrfCookieName = "csrftoken"; axios.defaults.xsrfHeaderName = "X-CSRFToken"; axios.defaults.withCredentials = true; diff --git a/front/src/documentstasks/api.js b/front/src/documentstasks/api.js index f61e5d9e..53de89d8 100644 --- a/front/src/documentstasks/api.js +++ b/front/src/documentstasks/api.js @@ -1,6 +1,7 @@ import axios from "axios"; +import { SCRIPT_NAME } from '../scriptname.js'; -axios.defaults.baseURL = "/api"; +axios.defaults.baseURL = SCRIPT_NAME + '/api' axios.defaults.xsrfCookieName = "csrftoken"; axios.defaults.xsrfHeaderName = "X-CSRFToken"; axios.defaults.withCredentials = true; diff --git a/front/src/editor/api.js b/front/src/editor/api.js index 57903750..5ad3c00c 100644 --- a/front/src/editor/api.js +++ b/front/src/editor/api.js @@ -1,6 +1,7 @@ import axios from "axios"; +import { SCRIPT_NAME } from '../scriptname.js'; -axios.defaults.baseURL = "/api"; +axios.defaults.baseURL = SCRIPT_NAME + '/api' axios.defaults.xsrfCookieName = "csrftoken"; axios.defaults.xsrfHeaderName = "X-CSRFToken"; axios.defaults.withCredentials = true; diff --git a/front/src/image_cards.js b/front/src/image_cards.js index f41bac6e..e4b1fa6d 100644 --- a/front/src/image_cards.js +++ b/front/src/image_cards.js @@ -7,6 +7,8 @@ Dropzone.autoDiscover = false; var g_dragged = null; // Note: chrome doesn't understand dataTransfer very well var lastSelected = null; +import { SCRIPT_NAME } from './scriptname.js'; + function openWizard(proc) { var selected_num = partCard.getSelectedPks().length; @@ -115,7 +117,7 @@ class partCard { this.progressBar.css("width", this.progress + "%"); this.progressBar.text(this.progress + "%"); this.updateWorkflowIcons(); - var url = "/document/" + DOCUMENT_ID + "/part/" + this.pk + "/edit/"; + var url = SCRIPT_NAME + "/document/" + DOCUMENT_ID + "/part/" + this.pk + "/edit/"; // show avg confidence on the card var avgConfidenceElement = this.progressBar; @@ -486,9 +488,9 @@ export function bootImageCards( ) { DOCUMENT_ID = documentId; API = { - document: "/api/documents/" + DOCUMENT_ID, - parts: "/api/documents/" + DOCUMENT_ID + "/parts/", - part: "/api/documents/" + DOCUMENT_ID + "/parts/{part_pk}/", + document: SCRIPT_NAME + "/api/documents/" + DOCUMENT_ID, + parts: SCRIPT_NAME + "/api/documents/" + DOCUMENT_ID + "/parts/", + part: SCRIPT_NAME + "/api/documents/" + DOCUMENT_ID + "/parts/{part_pk}/", }; //************* Card ordering ************* $("#cards-container").on("dragover", ".js-drop", function (ev) { diff --git a/front/src/messages.js b/front/src/messages.js index c27ed886..468acbd8 100644 --- a/front/src/messages.js +++ b/front/src/messages.js @@ -1,5 +1,7 @@ export var msgSocket; +import { SCRIPT_NAME } from './scriptname.js'; + var alerts = {}; export class Alert { constructor(id, message, level, links) { @@ -61,7 +63,7 @@ export class Alert { export function bootWebsocket() { let scheme = location.protocol === "https:" ? "wss:" : "ws:"; msgSocket = new ReconnectingWebSocket( - scheme + "//" + window.location.host + "/ws/notif/", + scheme + "//" + window.location.host + SCRIPT_NAME + "/ws/notif/", ); msgSocket.maxReconnectAttempts = 3; diff --git a/front/src/ontology_form.js b/front/src/ontology_form.js index be6f28b0..3acdd285 100644 --- a/front/src/ontology_form.js +++ b/front/src/ontology_form.js @@ -1,9 +1,11 @@ "use strict"; +import { SCRIPT_NAME } from './scriptname.js'; + export function bootOntologyForm() { /*** Region/Line types ***/ function pushType(type, name) { - let uri = "/api/types/" + type + "/"; + let uri = SCRIPT_NAME + "/api/types/" + type + "/"; return fetch(uri, { method: "post", credentials: "same-origin", diff --git a/front/src/scriptname.js b/front/src/scriptname.js new file mode 100644 index 00000000..c9ac46a7 --- /dev/null +++ b/front/src/scriptname.js @@ -0,0 +1,7 @@ +function scriptName() { + let prefix = document.currentScript.src.split('/').slice(3, -2).join('/'); + return (prefix.length > 0 ? "/" + prefix : ""); +} + +//export const SCRIPT_NAME = scriptName(); +export const SCRIPT_NAME = '/escriptorium2'; diff --git a/front/src/stories/DocumentDashboard.stories.js b/front/src/stories/DocumentDashboard.stories.js index dda07929..bee1d44d 100644 --- a/front/src/stories/DocumentDashboard.stories.js +++ b/front/src/stories/DocumentDashboard.stories.js @@ -1,6 +1,7 @@ import axios from "axios"; import MockAdapter from "axios-mock-adapter"; import { Server } from "mock-socket"; +import { SCRIPT_NAME } from '../scriptname.js'; import DocumentDashboard from "../../vue/pages/Document/Document.vue"; import GlobalNavigation from "../../vue/components/GlobalNavigation/GlobalNavigation.vue"; import { @@ -30,7 +31,7 @@ export default { // mock dropzone image upload api endpoint mockData: [ { - url: "/api/documents/1/parts", + url: SCRIPT_NAME + "/api/documents/1/parts", method: "POST", status: 201, }, @@ -146,7 +147,7 @@ const Template = (args, { argTypes }) => ({ setup() { // setup websocket mocks for tasks const scheme = location.protocol === "https:" ? "wss:" : "ws:"; - const mockSocketURL = `${scheme}//${window.location.host}/ws/notif/`; + const mockSocketURL = `${scheme}//${window.location.host}${SCRIPT_NAME}/ws/notif/`; // wrap in try/catch in case reloaded with mock socket still open try { const mockServer = new Server(mockSocketURL); diff --git a/front/vue/components/GlobalNavigation/GlobalNavigation.vue b/front/vue/components/GlobalNavigation/GlobalNavigation.vue index 88040139..5e71c674 100644 --- a/front/vue/components/GlobalNavigation/GlobalNavigation.vue +++ b/front/vue/components/GlobalNavigation/GlobalNavigation.vue @@ -2,7 +2,7 @@