Skip to content

Commit

Permalink
EDM-480/Add gids prefix to urls (#1328)
Browse files Browse the repository at this point in the history
* Add gids prefix to urls

* Dynamically get pathname for upload.js
  • Loading branch information
jefftmarks authored Feb 26, 2025
1 parent 9202a73 commit 1378b09
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Empty file modified Gemfile.lock
100644 → 100755
Empty file.
22 changes: 15 additions & 7 deletions app/assets/javascripts/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ $(function() {
);
});

// ASYNC UPLOAD LOGIC
const getPathPrefix = () => {
const hostname = window.location.hostname
const subdomain = hostname.split('.')[0];
return subdomain === 'localhost' ? '' : '/gids'
};
const PATH_PREFIX = getPathPrefix();;

// Open dialog during initial async upload to disable page
$("#async-upload-dialog").dialog({
autoOpen: false,
Expand Down Expand Up @@ -53,7 +61,7 @@ $(function() {
$(icon).off("click mouseleave");
try {
await $.ajax({
url: `/uploads/${uploadId}/cancel`,
url: `${PATH_PREFIX}/uploads/${uploadId}/cancel`,
type: "PATCH",
contentType: false,
processData: false,
Expand All @@ -79,7 +87,7 @@ $(function() {
const { uploadId, csvType } = $(this).data();
$(this).html(
`<p>${csvType} file upload complete</p>` +
'<p>Click ' + `<a href="/uploads/${uploadId}">here</a>` +
'<p>Click ' + `<a href="${PATH_PREFIX}/uploads/${uploadId}">here</a>` +
' for a more detailed report</p>'
);
}
Expand All @@ -100,7 +108,7 @@ $(function() {
try {
const xhr = new XMLHttpRequest();
const getUploadStatus = () => {
xhr.open("GET", `/uploads/${uploadId}/status`);
xhr.open("GET", `${PATH_PREFIX}/uploads/${uploadId}/status`);
xhr.send();
};
xhr.onload = function() {
Expand Down Expand Up @@ -139,7 +147,7 @@ $(function() {
$(uploadStatusDiv).html(capitalize(ok ? "succeeded" : "failed", titlecase));
}
// If on upload#show page, reload page to render flash alerts
if (window.location.pathname === `/uploads/${uploadId}`) {
if (window.location.pathname === `${PATH_PREFIX}/uploads/${uploadId}`) {
window.location.reload();
// Otherwise render link to alerts in pop dialog
} else if (!canceled) {
Expand Down Expand Up @@ -228,7 +236,7 @@ $(function() {
formData.set("upload[metadata][count][current]", i + 1);
formData.set("upload[metadata][count][total]", blobs.length);
const response = await $.ajax({
url: "/uploads",
url: `${PATH_PREFIX}/uploads`,
type: "POST",
data: formData,
dataType: "json",
Expand All @@ -239,10 +247,10 @@ $(function() {
}
// If successful, save upload ID in local storage to enable status polling
addToQueue(uploadId);
window.location.href = `/uploads/${uploadId}`;
window.location.href = `${PATH_PREFIX}/uploads/${uploadId}`;
} catch(error) {
console.error(error);
window.location.href = `/uploads/new/${csvType}`;
window.location.href = `${PATH_PREFIX}/uploads/new/${csvType}`;
}
};

Expand Down

0 comments on commit 1378b09

Please sign in to comment.