Merge branch 'feature/base-url' of https://github.com/AndreiArdelean1/crontab-ui into AndreiArdelean1-feature/base-url

pull/156/head
alse 4 years ago
commit 6f03bcdfee

@ -11,6 +11,10 @@ var mime = require('mime-types');
var fs = require('fs'); var fs = require('fs');
var busboy = require('connect-busboy'); // for file upload var busboy = require('connect-busboy'); // for file upload
// base url
var base_url = require("./routes").base_url
app.locals.baseURL = base_url
// basic auth // basic auth
var BASIC_AUTH_USER = process.env.BASIC_AUTH_USER; var BASIC_AUTH_USER = process.env.BASIC_AUTH_USER;
var BASIC_AUTH_PWD = process.env.BASIC_AUTH_PWD; var BASIC_AUTH_PWD = process.env.BASIC_AUTH_PWD;
@ -43,10 +47,10 @@ app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
app.use(busboy()); // to support file uploads app.use(busboy()); // to support file uploads
// include all folders // include all folders
app.use(express.static(__dirname + '/public')); app.use(base_url, express.static(__dirname + '/public'));
app.use(express.static(__dirname + '/public/css')); app.use(base_url, express.static(__dirname + '/public/css'));
app.use(express.static(__dirname + '/public/js')); app.use(base_url, express.static(__dirname + '/public/js'));
app.use(express.static(__dirname + '/config')); app.use(base_url, express.static(__dirname + '/config'));
app.set('views', __dirname + '/views'); app.set('views', __dirname + '/views');
// set host to 127.0.0.1 or the value set by environment var HOST // set host to 127.0.0.1 or the value set by environment var HOST
@ -273,5 +277,5 @@ app.listen(app.get('port'), app.get('host'), function() {
crontab.reload_db(); 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);
}); });

@ -1,10 +1,16 @@
exports.routes = { // base url
"root" : "/", var base_url = process.env.BASE_URL ?? '';
"save" : "/save", base_url = base_url.replace(/\/+$/, "").trim();
"run" : "/runjob",
"crontab" : "/crontab", exports.base_url = base_url;
"stop" : "/stop",
"start" : "/start", var routes = {
"root": "/",
"save": "/save",
"run": "/runjob",
"crontab": "/crontab",
"stop": "/stop",
"start": "/start",
"remove": "/remove", "remove": "/remove",
"backup": "/backup", "backup": "/backup",
"restore": "/restore", "restore": "/restore",
@ -17,5 +23,7 @@ exports.routes = {
"stdout": "/stdout", "stdout": "/stdout",
}; };
exports.relative = Object.keys(exports.routes).reduce((p, c) => ({...p, [c]: exports.routes[c].replace(/^\//, '')}), {}); exports.routes = Object.keys(routes).reduce((p, c) => ({...p, [c]: base_url + routes[c]}), {});
exports.relative["root"] = ".";
exports.relative = Object.keys(routes).reduce((p, c) => ({...p, [c]: routes[c].replace(/^\//, '')}), {});
exports.relative["root"] = base_url;

@ -6,7 +6,7 @@
<script src="bootstrap.min.js"></script> <script src="bootstrap.min.js"></script>
<script src="mailconfig.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> <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"/> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css"/>
<script type="text/javascript"> <script type="text/javascript">
var crontabs = []; var crontabs = [];

@ -4,7 +4,7 @@
<script src="jquery.js"></script> <script src="jquery.js"></script>
<script src="script.js"></script> <script src="script.js"></script>
<script src="bootstrap.min.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"> <script type="text/javascript">
var crontabs = []; var crontabs = [];
var routes = []; var routes = [];

Loading…
Cancel
Save