From a67981fde16bf975985933bdbdbf220338870650 Mon Sep 17 00:00:00 2001 From: Andrey Alcheev Date: Thu, 15 Feb 2018 22:58:38 +0500 Subject: [PATCH] Make all the paths relative. This allows the application work behind a reverse proxy with any URL prepended. --- app.js | 13 ++++++++++--- public/js/script.js | 4 ++-- views/index.ejs | 2 +- views/restore.ejs | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index be68cd4..4810521 100755 --- a/app.js +++ b/app.js @@ -12,6 +12,14 @@ var busboy = require('connect-busboy'); // for file upload // include the routes var routes = require("./routes").routes; +var js_routes = {}; +for (var key in routes) { + var js_route = routes[key]; + if (/^\/./.test(js_route)) { + js_route = js_route.replace(/^\//, ''); + } + js_routes[key] = js_route; +} // set the view engine to ejs app.set('view engine', 'ejs'); @@ -25,7 +33,6 @@ app.use(busboy()); // to support file uploads // include all folders app.use(express.static(__dirname + '/public')); -app.use(express.static(__dirname + '/public/css')); app.use(express.static(__dirname + '/public/js')); app.use(express.static(__dirname + '/config')); app.set('views', __dirname + '/views'); @@ -43,7 +50,7 @@ app.get(routes.root, function(req, res) { // send all the required parameters crontab.crontabs( function(docs){ res.render('index', { - routes : JSON.stringify(routes), + routes : JSON.stringify(js_routes), crontabs : JSON.stringify(docs), backups : crontab.get_backup_names(), env : crontab.get_env(), @@ -106,7 +113,7 @@ app.get(routes.restore, function(req, res) { // get all the crontabs restore.crontabs(req.query.db, function(docs){ res.render('restore', { - routes : JSON.stringify(routes), + routes : JSON.stringify(js_routes), crontabs : JSON.stringify(docs), backups : crontab.get_backup_names(), db: req.query.db diff --git a/public/js/script.js b/public/js/script.js index 5d08916..b87e056 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -160,7 +160,7 @@ function doBackup(){ function delete_backup(db_name){ messageBox("

Do you want to delete this backup?

", "Confirm delete", null, null, function(){ $.get(routes.delete_backup, {db: db_name}, function(){ - location = routes.root; + location = '.'; }); }); } @@ -168,7 +168,7 @@ function delete_backup(db_name){ function restore_backup(db_name){ messageBox("

Do you want to restore this backup?

", "Confirm restore", null, null, function(){ $.get(routes.restore_backup, {db: db_name}, function(){ - location = routes.root; + location = '.'; }); }); } diff --git a/views/index.ejs b/views/index.ejs index a972b39..b2c63e1 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -6,7 +6,7 @@ - + - +