diff --git a/app/routes/private_routes.js b/app/routes/private_routes.js index 897592a..1b934ca 100644 --- a/app/routes/private_routes.js +++ b/app/routes/private_routes.js @@ -14,6 +14,7 @@ function errorPageRenderer(res, emoji, message) { res.render("error", { page_title: app_conf.name, program: app_conf.program, + app_url: app_conf.app_url, css_path: path.join(app_conf.paths.css.web, "stylesheet.css"), js_path: path.join(app_conf.paths.js.web, "error.js"), error_emoji: emoji, @@ -182,6 +183,7 @@ router.get("/add", async (req, res) => { res.render("add", { page_title: app_conf.name, program: app_conf.program, + app_url: app_conf.app_url, css_path: path.join(app_conf.paths.css.web, "stylesheet.css"), js_path: path.join(app_conf.paths.js.web, "add.js"), column_options: JSON.stringify(column_options), @@ -249,6 +251,7 @@ router.get("/edit", async (req, res) => { res.render("edit", { page_title: app_conf.name, program: app_conf.program, + app_url: app_conf.app_url, css_path: path.join(app_conf.paths.css.web, "stylesheet.css"), js_path: path.join(app_conf.paths.js.web, "edit.js"), column_options: JSON.stringify(column_options), @@ -297,6 +300,7 @@ router.get("/", async (req, res) => { res.render("index", { page_title: app_conf.name, program: app_conf.program, + app_url: app_conf.app_url, css_path: path.join(app_conf.paths.css.web, "stylesheet.css"), js_path: path.join(app_conf.paths.js.web, "index.js"), table_header: table_header, @@ -315,6 +319,7 @@ router.get("/about", (req, res) => { res.render("about", { page_title: app_conf.name, program: app_conf.program, + app_url: app_conf.app_url, css_path: path.join(app_conf.paths.css.web, "stylesheet.css"), version: app_conf.version }); diff --git a/app/routes/public_routes.js b/app/routes/public_routes.js index 2c4e015..0bed904 100644 --- a/app/routes/public_routes.js +++ b/app/routes/public_routes.js @@ -11,13 +11,7 @@ router.use(app_conf.paths.js.web, express.static(path.join(path.dirname(require. * Main endpoint - might implement authentication step here... */ router.get("/", (req, res) => { - res.render("auth", { - page_title: app_conf.name, - css_path: path.join(app_conf.paths.css.web, "stylesheet.css"), - protocol: app_conf.protocol, - host: app_conf.host, - port: app_conf.port - }); + res.redirect(`${app_conf.protocol}://${app_conf.host}:${app_conf.port}${app_conf.app_url}`); }); module.exports = router; \ No newline at end of file diff --git a/app/views/about.ejs b/app/views/about.ejs index c020fa0..0da6861 100644 --- a/app/views/about.ejs +++ b/app/views/about.ejs @@ -30,7 +30,7 @@ style="font-size: 150%;">GitHub
- 🢀 Return + 🢀 Return diff --git a/app/views/add.ejs b/app/views/add.ejs index 9c9afdc..5872830 100644 --- a/app/views/add.ejs +++ b/app/views/add.ejs @@ -16,6 +16,7 @@ @@ -35,12 +36,12 @@ <%- table_data %>
- 🢀 Return + 🢀 Return
-
About
+
About
diff --git a/app/views/auth.ejs b/app/views/auth.ejs deleted file mode 100644 index a7b2fe1..0000000 --- a/app/views/auth.ejs +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - <%= page_title %> - - - - - - - - - - -
- -
-
-
- - Enter -
-
- - - \ No newline at end of file diff --git a/app/views/edit.ejs b/app/views/edit.ejs index 6b3e499..418a5a4 100644 --- a/app/views/edit.ejs +++ b/app/views/edit.ejs @@ -16,6 +16,7 @@ @@ -38,12 +39,12 @@ <%- table_data %>
- 🢀 Return + 🢀 Return
-
About
+
About
diff --git a/app/views/error.ejs b/app/views/error.ejs index 3b47fd0..c19a494 100644 --- a/app/views/error.ejs +++ b/app/views/error.ejs @@ -14,6 +14,9 @@ rel="stylesheet"> + @@ -39,7 +42,7 @@ <%= error_message %>
-
🢀 Return + 🢀 Return diff --git a/app/views/index.ejs b/app/views/index.ejs index 05c2523..14deb4e 100644 --- a/app/views/index.ejs +++ b/app/views/index.ejs @@ -14,6 +14,9 @@ rel="stylesheet"> + @@ -42,7 +45,7 @@
-
About
+
About
diff --git a/samples/app.conf.sample b/samples/app.conf.sample index c25172d..46019dd 100644 --- a/samples/app.conf.sample +++ b/samples/app.conf.sample @@ -4,7 +4,8 @@ module.exports = { program: "SQLite3", host: "localhost", protocol: "http", - port: 80, + port: 8080, + app_url: "/app", username: "admin", password: "password", logger: { diff --git a/server.js b/server.js index 207334d..d26319d 100644 --- a/server.js +++ b/server.js @@ -24,9 +24,8 @@ app.use(fileUpload({ tempFileDir: path.join(__dirname, app_conf.temp_directory) })); -app.use("/", public_routes); - -app.use("/app", basicAuth({ +app.use(`/`, public_routes); +app.use(`${app_conf.app_url}`, basicAuth({ users: { [app_conf.username]: app_conf.password }, @@ -40,7 +39,7 @@ app.use("/app", basicAuth({ app.set("view engine", "ejs"); app.set("views", path.join(__dirname, app_conf.views_directory)); const server = app.listen(app_conf.port, (error) => { - logger.info("Starting Database Editor."); + logger.info(`Starting ${app_conf.name} ${app_conf.program}.`); db.connect(); fs.rm(path.join(__dirname, app_conf.temp_directory, "/."), { recursive: true }, (error) => { if (error == null) { diff --git a/src/javascript/add.js b/src/javascript/add.js index a52ea11..ca2bcc4 100644 --- a/src/javascript/add.js +++ b/src/javascript/add.js @@ -20,7 +20,7 @@ commit.ondblclick = async function () { } try { - const response = await fetch(`/app/add?element=${sql_row[1].cells[0].firstChild.value}`, { + const response = await fetch(`${app_url}/add?element=${sql_row[1].cells[0].firstChild.value}`, { method: "POST", body: JSON.stringify(req_body), headers: { @@ -31,7 +31,7 @@ commit.ondblclick = async function () { throw new Error(`Response status: ${response.status}`); } else { this.style.backgroundColor = "blue"; - window.location.href = "/app"; + window.location.href = app_url; } } catch (error) { alert(`Add unsuccessful. ${error.message}`); diff --git a/src/javascript/edit.js b/src/javascript/edit.js index a2b3cd5..829599d 100644 --- a/src/javascript/edit.js +++ b/src/javascript/edit.js @@ -22,13 +22,13 @@ function setEventListeners(element, cb) { setEventListeners(remove, async () => { try { - const response = await fetch(`/app/remove?element=${sql_row[1].cells[0].firstChild.textContent}`, { + const response = await fetch(`${app_url}/remove?element=${sql_row[1].cells[0].firstChild.textContent}`, { method: "DELETE" }); if (!response.ok) { throw new Error(`Response status: ${response.status}`); } else { - window.location.href = "/app"; + window.location.href = app_url; } } catch (error) { alert(`Remove unsuccessful. ${error.message}`); @@ -46,7 +46,7 @@ setEventListeners(commit, async () => { } try { - const response = await fetch(`/app/edit?element=${sql_row[1].cells[0].firstChild.textContent}`, { + const response = await fetch(`${app_url}/edit?element=${sql_row[1].cells[0].firstChild.textContent}`, { method: "POST", body: JSON.stringify(req_body), headers: { @@ -56,7 +56,7 @@ setEventListeners(commit, async () => { if (!response.ok) { throw new Error(`Response status: ${response.status}`); } else { - window.location.href = "/app"; + window.location.href = app_url; } } catch (error) { alert(`Edit unsuccessful. ${error.message}`); diff --git a/src/javascript/error.js b/src/javascript/error.js index 5ea99ba..0d9a0a9 100644 --- a/src/javascript/error.js +++ b/src/javascript/error.js @@ -24,7 +24,7 @@ setEventListeners(upload, async () => { const formData = new FormData(); formData.append('file', file); - fetch('/app/upload', { + fetch(`${app_url}/upload`, { method: 'POST', body: formData }).then((response) => { @@ -41,7 +41,7 @@ setEventListeners(upload, async () => { }); setEventListeners(download, () => { - window.location.href = "/app/download"; + window.location.href = `${app_url}/download`; }); setEventListeners(logout, () => { diff --git a/src/javascript/index.js b/src/javascript/index.js index ed4e0da..86062ec 100644 --- a/src/javascript/index.js +++ b/src/javascript/index.js @@ -26,7 +26,7 @@ setEventListeners(upload, async () => { const formData = new FormData(); formData.append('file', file); - fetch('/app/upload', { + fetch(`${app_url}/upload`, { method: 'POST', body: formData }).then((response) => { @@ -43,11 +43,11 @@ setEventListeners(upload, async () => { }); setEventListeners(add, () => { - window.location.href = "/app/add"; + window.location.href = `${app_url}/add`; }); setEventListeners(download, () => { - window.location.href = "/app/download"; + window.location.href = `${app_url}/download`; }); setEventListeners(logout, () => { @@ -58,6 +58,6 @@ const sql_rows = sql_table.rows; for (let i = 1; i < sql_rows.length; i++) { setEventListeners(sql_rows[i], () => { - window.location.href = `/app/edit?element=${sql_rows[i].cells[0].innerText}`; + window.location.href = `${app_url}/edit?element=${sql_rows[i].cells[0].innerText}`; }); } \ No newline at end of file