Skip to content

Commit

Permalink
#322 Add ROOT_PATH, Deprecate PUBLIC_URL (#323)
Browse files Browse the repository at this point in the history
* #322 ROOT_PATH, doesn't work fully for /configure yet

* #322 ROOT_PATH for runtime subpaths

* #322 Remove PUBLIC_URL and fix ROOT_PATH css
  • Loading branch information
tariqksoliman committed Feb 2, 2023
1 parent e959617 commit a2bef30
Show file tree
Hide file tree
Showing 24 changed files with 285 additions and 108 deletions.
4 changes: 2 additions & 2 deletions API/Backend/Config/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let setup = {
process.env.HIDE_CONFIG != "true"
) {
s.app.get(
"/configure",
s.ROOT_PATH + "/configure",
s.ensureGroup(s.permissions.users),
s.ensureAdmin(true),
(req, res) => {
Expand All @@ -24,7 +24,7 @@ let setup = {
}

s.app.use(
"/API/configure",
s.ROOT_PATH + "/API/configure",
s.ensureAdmin(),
s.checkHeadersCodeInjection,
s.setContentType,
Expand Down
8 changes: 4 additions & 4 deletions API/Backend/Datasets/setup.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const router = require("./routes/datasets");
let setup = {
//Once the app initializes
onceInit: s => {
onceInit: (s) => {
s.app.use(
"/API/datasets",
s.ROOT_PATH + "/API/datasets",
s.ensureAdmin(),
s.checkHeadersCodeInjection,
s.setContentType,
router
);
},
//Once the server starts
onceStarted: s => {},
onceStarted: (s) => {},
//Once all tables sync
onceSynced: s => {}
onceSynced: (s) => {},
};

module.exports = setup;
4 changes: 2 additions & 2 deletions API/Backend/Draw/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let setup = {
//Once the app initializes
onceInit: (s) => {
s.app.use(
"/API/files",
s.ROOT_PATH + "/API/files",
s.ensureUser(),
s.checkHeadersCodeInjection,
s.setContentType,
Expand All @@ -15,7 +15,7 @@ let setup = {
);

s.app.use(
"/API/draw",
s.ROOT_PATH + "/API/draw",
s.ensureUser(),
s.checkHeadersCodeInjection,
s.setContentType,
Expand Down
8 changes: 4 additions & 4 deletions API/Backend/Geodatasets/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ const router = require("./routes/geodatasets");

let setup = {
//Once the app initializes
onceInit: s => {
onceInit: (s) => {
s.app.use(
"/API/geodatasets",
s.ROOT_PATH + "/API/geodatasets",
s.ensureAdmin(),
s.checkHeadersCodeInjection,
s.setContentType,
router
);
},
//Once the server starts
onceStarted: s => {},
onceStarted: (s) => {},
//Once all tables sync
onceSynced: s => {}
onceSynced: (s) => {},
};

module.exports = setup;
8 changes: 4 additions & 4 deletions API/Backend/LongTermToken/setup.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const router = require("./routes/longtermtokens");
let setup = {
//Once the app initializes
onceInit: s => {
onceInit: (s) => {
s.app.use(
"/API/longtermtoken",
s.ROOT_PATH + "/API/longtermtoken",
s.ensureAdmin(false, true),
s.checkHeadersCodeInjection,
s.setContentType,
router
);
},
//Once the server starts
onceStarted: s => {},
onceStarted: (s) => {},
//Once all tables sync
onceSynced: s => {}
onceSynced: (s) => {},
};

module.exports = setup;
8 changes: 4 additions & 4 deletions API/Backend/Shortener/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ const router = require("./routes/shortener");

let setup = {
//Once the app initializes
onceInit: s => {
onceInit: (s) => {
s.app.use(
"/API/shortener",
s.ROOT_PATH + "/API/shortener",
s.ensureUser(),
s.checkHeadersCodeInjection,
s.setContentType,
router
);
},
//Once the server starts
onceStarted: s => {},
onceStarted: (s) => {},
//Once all tables sync
onceSynced: s => {}
onceSynced: (s) => {},
};

module.exports = setup;
2 changes: 1 addition & 1 deletion API/Backend/Users/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const router = require("./routes/users");
let setup = {
//Once the app initializes
onceInit: (s) => {
s.app.use("/API/users", s.checkHeadersCodeInjection, router);
s.app.use(s.ROOT_PATH + "/API/users", s.checkHeadersCodeInjection, router);
},
//Once the server starts
onceStarted: (s) => {},
Expand Down
7 changes: 6 additions & 1 deletion API/Backend/Utils/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ const router = require("./routes/utils");
let setup = {
//Once the app initializes
onceInit: (s) => {
s.app.use("/API/utils", s.ensureUser(), s.setContentType, router);
s.app.use(
s.ROOT_PATH + "/API/utils",
s.ensureUser(),
s.setContentType,
router
);
},
//Once the server starts
onceStarted: (s) => {},
Expand Down
8 changes: 6 additions & 2 deletions API/Backend/Webhooks/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ const routerTestWebhooks = require("./routes/testwebhooks");
let setup = {
//Once the app initializes
onceInit: (s) => {
s.app.use("/API/webhooks", s.checkHeadersCodeInjection, routerWebhooks);
s.app.use(
s.ROOT_PATH + "/API/webhooks",
s.checkHeadersCodeInjection,
routerWebhooks
);
if (process.env.NODE_ENV === "development") {
s.app.use(
"/API/testwebhooks",
s.ROOT_PATH + "/API/testwebhooks",
s.checkHeadersCodeInjection,
routerTestWebhooks
);
Expand Down
8 changes: 4 additions & 4 deletions API/Backend/setupTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const router = require("./routes/your_router");

let setup = {
//Once the app initializes
onceInit: s => {},
onceInit: (s) => {},
//Once the server starts
onceStarted: s => {},
onceStarted: (s) => {},
//Once all tables sync
onceSynced: s => {},
envs: [{ name: "ENV_VAR", description: "", required: false, private: false }]
onceSynced: (s) => {},
envs: [{ name: "ENV_VAR", description: "", required: false, private: false }],
};

module.exports = setup;
4 changes: 3 additions & 1 deletion config/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ function initialize() {
url: calls.logout.url,
data: {},
success: function (data) {
window.location = "/";
// Remove last directory from pathname
const path = window.location.pathname.split("/");
window.location.href = path.slice(0, path.length - 1).join("/") || "/";
},
});
});
Expand Down
13 changes: 4 additions & 9 deletions config/login/adminlogin.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
@font-face {
font-family: "Source Sans Pro";
src: url(public/fonts/sourcesanspro/SourceSansPro-Regular.ttf);
}

body,
html {
font-family: "Source Sans Pro", sans-serif;
font-family: sans-serif;
background-color: #1a1a1a;
padding: 0;
margin: 0;
Expand All @@ -27,7 +22,7 @@ html {
}

.box h4 {
font-family: "Source Sans Pro", sans-serif;
font-family: sans-serif;
color: #08aeea;
font-size: 18px;
margin-top: 94px;
Expand All @@ -39,7 +34,7 @@ html {
}

.box h5 {
font-family: "Source Sans Pro", sans-serif;
font-family: sans-serif;
font-size: 13px;
color: #a1a4ad;
letter-spacing: 1.5px;
Expand Down Expand Up @@ -94,7 +89,7 @@ a:hover {
cursor: pointer;
text-align: center;
user-select: none;
font-family: "Source Sans Pro", sans-serif;
font-family: sans-serif;
line-height: 49px;
}

Expand Down
12 changes: 3 additions & 9 deletions config/login/adminlogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ function setupLogin() {
});
}

// Is used in views/configure.pug
function back() {
window.location = window.location.substring(
0,
window.location.lastIndexOf("/")
);
}

$(document).ready(function () {
$(document).on("keypress", function (e) {
if (e.which == 13) {
Expand All @@ -132,6 +124,8 @@ $(document).ready(function () {
});

$("#backIcon").on("click", function () {
window.location.href = "/";
// Remove last directory from pathname
const path = window.location.pathname.split("/");
window.location.href = path.slice(0, path.length - 1).join("/") || "/";
});
});
117 changes: 117 additions & 0 deletions config/pre/RefreshAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//function from https://stackoverflow.com/questions/6312993/javascript-seconds-to-time-string-with-format-hhmmss
String.prototype.toHHMMSS = function () {
var sec_num = parseInt(this, 10) // don't forget the second param
var hours = Math.floor(sec_num / 3600)
var minutes = Math.floor((sec_num - hours * 3600) / 60)
var seconds = sec_num - hours * 3600 - minutes * 60

if (hours < 10) {
hours = '0' + hours
}
if (minutes < 10) {
minutes = '0' + minutes
}
if (seconds < 10) {
seconds = '0' + seconds
}
return hours + ':' + minutes + ':' + seconds
}

//set interval that checks valid sso
//every 4:30min checks if the token will expire in less than 5min
//refreshes if the user moved their mouse in the past 20min
if (mmgisglobal.SERVER == 'node' && mmgisglobal.AUTH == 'csso') {
console.log(
'%cAUTH_REFRESH ON',
'background: #006280; padding: 0px 4px 0px 4px;'
)
//Add your own login/logout redirects
function ssologout() {
window.location.href = '/ssologoutredirect'
}
function ssologin() {
window.location.href =
'/ssologinredirect?redirect=' + window.location.href
}

mmgisglobal.lastInteraction = Math.floor(Date.now() / 1000)
var _refreshAuth_checkEvery = 60000 * 10 //milliseconds
var _refreshAuth_expiringLessThan = 60 * 11 //seconds
var _refreshAuth_interactedPast = 60000 * 30 //milliseconds

function ssorefresh() {
var request = new XMLHttpRequest()
request.open('Post', '/ssostatus', true)
request.onload = function () {
if (request.status >= 200 && request.status < 400) {
var result = request.responseText
result = JSON.parse(result)

var now = Math.floor(Date.now() / 1000)

if (mmgisglobal.SHOW_AUTH_TIMEOUT) {
var append = false

var elm = document.getElementById('AUTH_TIMEOUT')
if (elm == null) {
elm = document.createElement('div')
append = true
}
elm.id = 'AUTH_TIMEOUT'
elm.style.cssText =
'position:fixed;left:225px;bottom:0px;z-index:11000;font-family:monospace;font-size:11px;color:#121626;'
elm.innerHTML =
'Authentication expiring in ' +
(result.exp - now).toString().toHHMMSS() +
'<div onclick="ssologin()" style="cursor:pointer;">Login again to renew</div>'

if (append) document.body.appendChild(elm)
}

if (result.authenticated) {
if (
mmgisglobal.lastInteraction +
_refreshAuth_interactedPast <=
now
) {
ssologout()
} else if (
now + _refreshAuth_expiringLessThan >=
result.inactivity_timeout
) {
var refresh = new XMLHttpRequest()
refresh.open('Post', '/ssorefreshtimeout', true)
refresh.onload = function () {
if (refresh.status >= 200 && refresh.status < 400) {
var result = refresh.responseText
result = JSON.parse(result)
if (!result.success) {
ssologout()
}
} else {
ssologout()
}
}
refresh.onerror = function () {
ssologout()
}
refresh.send()
}
} else {
ssologout()
}
} else {
ssologout()
}
}

request.onerror = function () {
ssologout()
}

request.send()
}

ssorefresh()
setInterval(ssorefresh, _refreshAuth_checkEvery)
}
4 changes: 4 additions & 0 deletions configuration/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function getClientEnvironment(publicUrl) {
// This should only be used as an escape hatch. Normally you would put
// images into the `src` and `import` them in code to get their paths.
PUBLIC_URL: publicUrl,
ROOT_PATH:
(process.env.NODE_ENV || "development") === "development"
? ""
: process.env.ROOT_PATH || "",
// We support configuring the sockjs pathname during development.
// These settings let a developer run multiple simultaneous projects.
// They are used as the connection `hostname`, `pathname` and `port`
Expand Down
Loading

0 comments on commit a2bef30

Please sign in to comment.