Skip to content

Commit 1378b09

Browse files
authored
EDM-480/Add gids prefix to urls (#1328)
* Add gids prefix to urls * Dynamically get pathname for upload.js
1 parent 9202a73 commit 1378b09

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

Gemfile.lock

100644100755
File mode changed.

app/assets/javascripts/upload.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ $(function() {
77
);
88
});
99

10+
// ASYNC UPLOAD LOGIC
11+
const getPathPrefix = () => {
12+
const hostname = window.location.hostname
13+
const subdomain = hostname.split('.')[0];
14+
return subdomain === 'localhost' ? '' : '/gids'
15+
};
16+
const PATH_PREFIX = getPathPrefix();;
17+
1018
// Open dialog during initial async upload to disable page
1119
$("#async-upload-dialog").dialog({
1220
autoOpen: false,
@@ -53,7 +61,7 @@ $(function() {
5361
$(icon).off("click mouseleave");
5462
try {
5563
await $.ajax({
56-
url: `/uploads/${uploadId}/cancel`,
64+
url: `${PATH_PREFIX}/uploads/${uploadId}/cancel`,
5765
type: "PATCH",
5866
contentType: false,
5967
processData: false,
@@ -79,7 +87,7 @@ $(function() {
7987
const { uploadId, csvType } = $(this).data();
8088
$(this).html(
8189
`<p>${csvType} file upload complete</p>` +
82-
'<p>Click ' + `<a href="/uploads/${uploadId}">here</a>` +
90+
'<p>Click ' + `<a href="${PATH_PREFIX}/uploads/${uploadId}">here</a>` +
8391
' for a more detailed report</p>'
8492
);
8593
}
@@ -100,7 +108,7 @@ $(function() {
100108
try {
101109
const xhr = new XMLHttpRequest();
102110
const getUploadStatus = () => {
103-
xhr.open("GET", `/uploads/${uploadId}/status`);
111+
xhr.open("GET", `${PATH_PREFIX}/uploads/${uploadId}/status`);
104112
xhr.send();
105113
};
106114
xhr.onload = function() {
@@ -139,7 +147,7 @@ $(function() {
139147
$(uploadStatusDiv).html(capitalize(ok ? "succeeded" : "failed", titlecase));
140148
}
141149
// If on upload#show page, reload page to render flash alerts
142-
if (window.location.pathname === `/uploads/${uploadId}`) {
150+
if (window.location.pathname === `${PATH_PREFIX}/uploads/${uploadId}`) {
143151
window.location.reload();
144152
// Otherwise render link to alerts in pop dialog
145153
} else if (!canceled) {
@@ -228,7 +236,7 @@ $(function() {
228236
formData.set("upload[metadata][count][current]", i + 1);
229237
formData.set("upload[metadata][count][total]", blobs.length);
230238
const response = await $.ajax({
231-
url: "/uploads",
239+
url: `${PATH_PREFIX}/uploads`,
232240
type: "POST",
233241
data: formData,
234242
dataType: "json",
@@ -239,10 +247,10 @@ $(function() {
239247
}
240248
// If successful, save upload ID in local storage to enable status polling
241249
addToQueue(uploadId);
242-
window.location.href = `/uploads/${uploadId}`;
250+
window.location.href = `${PATH_PREFIX}/uploads/${uploadId}`;
243251
} catch(error) {
244252
console.error(error);
245-
window.location.href = `/uploads/new/${csvType}`;
253+
window.location.href = `${PATH_PREFIX}/uploads/new/${csvType}`;
246254
}
247255
};
248256

0 commit comments

Comments
 (0)