Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for BASE_URL environment variables #139

Merged
merged 1 commit into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ var mime = require('mime-types');
var fs = require('fs');
var busboy = require('connect-busboy'); // for file upload

// base url
var base_url = require("./routes").base_url
app.locals.baseURL = base_url

// basic auth
var BASIC_AUTH_USER = process.env.BASIC_AUTH_USER;
var BASIC_AUTH_PWD = process.env.BASIC_AUTH_PWD;
Expand Down Expand Up @@ -43,10 +47,10 @@ app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
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.use(base_url, express.static(__dirname + '/public'));
app.use(base_url, express.static(__dirname + '/public/css'));
app.use(base_url, express.static(__dirname + '/public/js'));
app.use(base_url, express.static(__dirname + '/config'));
app.set('views', __dirname + '/views');

// set host to 127.0.0.1 or the value set by environment var HOST
Expand Down Expand Up @@ -271,5 +275,5 @@ app.listen(app.get('port'), app.get('host'), function() {

crontab.reload_db();
}
console.log("Crontab UI is running at http://" + app.get('host') + ":" + app.get('port'));
console.log("Crontab UI is running at http://" + app.get('host') + ":" + app.get('port') + base_url);
});
26 changes: 17 additions & 9 deletions routes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
exports.routes = {
"root" : "/",
"save" : "/save",
"run" : "/runjob",
"crontab" : "/crontab",
"stop" : "/stop",
"start" : "/start",
// base url
var base_url = process.env.BASE_URL ?? '';
base_url = base_url.replace(/\/+$/, "").trim();

exports.base_url = base_url;

var routes = {
"root": "/",
"save": "/save",
"run": "/runjob",
"crontab": "/crontab",
"stop": "/stop",
"start": "/start",
"remove": "/remove",
"backup": "/backup",
"restore": "/restore",
Expand All @@ -17,5 +23,7 @@ exports.routes = {
"stdout": "/stdout",
};

exports.relative = Object.keys(exports.routes).reduce((p, c) => ({...p, [c]: exports.routes[c].replace(/^\//, '')}), {});
exports.relative["root"] = ".";
exports.routes = Object.keys(routes).reduce((p, c) => ({...p, [c]: base_url + routes[c]}), {});

exports.relative = Object.keys(routes).reduce((p, c) => ({...p, [c]: routes[c].replace(/^\//, '')}), {});
exports.relative["root"] = base_url;
2 changes: 1 addition & 1 deletion views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<script src="bootstrap.min.js"></script>
<script src="mailconfig.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs/dt-1.10.12/datatables.min.js"></script>
<link rel="stylesheet" href="bootstrap.min.css" />
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css"/>
<script type="text/javascript">
var crontabs = [];
Expand Down
2 changes: 1 addition & 1 deletion views/restore.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script src="jquery.js"></script>
<script src="script.js"></script>
<script src="bootstrap.min.js"></script>
<link rel="stylesheet" href="bootstrap.min.css" />
<link rel="stylesheet" href="css/bootstrap.min.css" />
<script type="text/javascript">
var crontabs = [];
var routes = [];
Expand Down