Skip to content

Commit 6f03bcd

Browse files
committed
Merge branch 'feature/base-url' of https://github.com/AndreiArdelean1/crontab-ui into AndreiArdelean1-feature/base-url
2 parents 64b5f0f + 63005e5 commit 6f03bcd

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

app.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ var mime = require('mime-types');
1111
var fs = require('fs');
1212
var busboy = require('connect-busboy'); // for file upload
1313

14+
// base url
15+
var base_url = require("./routes").base_url
16+
app.locals.baseURL = base_url
17+
1418
// basic auth
1519
var BASIC_AUTH_USER = process.env.BASIC_AUTH_USER;
1620
var BASIC_AUTH_PWD = process.env.BASIC_AUTH_PWD;
@@ -43,10 +47,10 @@ app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
4347
app.use(busboy()); // to support file uploads
4448

4549
// include all folders
46-
app.use(express.static(__dirname + '/public'));
47-
app.use(express.static(__dirname + '/public/css'));
48-
app.use(express.static(__dirname + '/public/js'));
49-
app.use(express.static(__dirname + '/config'));
50+
app.use(base_url, express.static(__dirname + '/public'));
51+
app.use(base_url, express.static(__dirname + '/public/css'));
52+
app.use(base_url, express.static(__dirname + '/public/js'));
53+
app.use(base_url, express.static(__dirname + '/config'));
5054
app.set('views', __dirname + '/views');
5155

5256
// 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() {
273277

274278
crontab.reload_db();
275279
}
276-
console.log("Crontab UI is running at http://" + app.get('host') + ":" + app.get('port'));
280+
console.log("Crontab UI is running at http://" + app.get('host') + ":" + app.get('port') + base_url);
277281
});

routes.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
exports.routes = {
2-
"root" : "/",
3-
"save" : "/save",
4-
"run" : "/runjob",
5-
"crontab" : "/crontab",
6-
"stop" : "/stop",
7-
"start" : "/start",
1+
// base url
2+
var base_url = process.env.BASE_URL ?? '';
3+
base_url = base_url.replace(/\/+$/, "").trim();
4+
5+
exports.base_url = base_url;
6+
7+
var routes = {
8+
"root": "/",
9+
"save": "/save",
10+
"run": "/runjob",
11+
"crontab": "/crontab",
12+
"stop": "/stop",
13+
"start": "/start",
814
"remove": "/remove",
915
"backup": "/backup",
1016
"restore": "/restore",
@@ -17,5 +23,7 @@ exports.routes = {
1723
"stdout": "/stdout",
1824
};
1925

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

views/index.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<script src="bootstrap.min.js"></script>
77
<script src="mailconfig.js"></script>
88
<script type="text/javascript" src="https://cdn.datatables.net/v/bs/dt-1.10.12/datatables.min.js"></script>
9-
<link rel="stylesheet" href="bootstrap.min.css" />
9+
<link rel="stylesheet" href="css/bootstrap.min.css" />
1010
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css"/>
1111
<script type="text/javascript">
1212
var crontabs = [];

views/restore.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<script src="jquery.js"></script>
55
<script src="script.js"></script>
66
<script src="bootstrap.min.js"></script>
7-
<link rel="stylesheet" href="bootstrap.min.css" />
7+
<link rel="stylesheet" href="css/bootstrap.min.css" />
88
<script type="text/javascript">
99
var crontabs = [];
1010
var routes = [];

0 commit comments

Comments
 (0)