Skip to content

Commit

Permalink
Merge pull request plexidev#65 from lieuwe-berg/quickdb
Browse files Browse the repository at this point in the history
Added suburl to webview
  • Loading branch information
lorencerri authored Apr 3, 2018
2 parents 9ebb1cf + 0888370 commit f80fe53
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
6 changes: 6 additions & 0 deletions docs/AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@
- **What you contributed:** *General Bugfixes*

---

- **Name/Username:** *lieuwe_berg*
- **Contact/Social Media:** *@lieuwe_berg#8662 on Discord*
- **What you contributed:** *Webviewer Suburl Feature*

---
45 changes: 34 additions & 11 deletions src/webviewer/createWebview.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,48 @@ const app = require('express')(),
*/

module.exports = {
createWebview: function(password, port) {
createWebview: function(password, port, suburl) {
// Verify Data
if (!password) return console.log('Invalid Password');
if (isNaN(port)) return console.log('Invalid Port');

// Routing
// If no suburl
if (!suburl) {
app.get("/", function(request, response) {
response.sendFile(__dirname + '/index.html')
})

app.get("/data", function(request, response) {
response.sendFile(__dirname + '/data.html')
})
} else {
// If suburl is a string
if (typeof suburl === 'string') {
app.get(`/${suburl}/`, function(request, response) {
response.sendFile(__dirname + '/index.html')
})

app.get(`/${suburl}/data`, function(request, response) {
response.sendFile(__dirname + '/data.html')
})
} else {
// If it's not a string, convert suburl to a string
let suburlString = String(suburl)
app.get(`/${suburlString}/`, function(request, response) {
response.sendFile(__dirname + '/index.html')
})

app.get(`/${suburl}/data`, function(request, response) {
response.sendFile(__dirname + '/data.html')
})
};
};

// Listening
server.listen(port, function() {
console.log(`Quick.db WebViewer: Listening to port ${port}`)
});

// Routing
app.get("/", function(request, response) {
response.sendFile(__dirname + '/index.html')
})

app.get("/data", function(request, response) {
response.sendFile(__dirname + '/data.html')
})

io.on('connection', function(socket) {
console.log('Connection Recieved...');

Expand Down
10 changes: 8 additions & 2 deletions src/webviewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,18 @@ <h1 class="display-4">Login</h1>
});
function dataView() {

location.replace(`${window.location.href}data/?password=${document.getElementById("inputPassword").value}`);
let loc = window.location;
let rootUrl = loc.protocol + '//' + loc.hostname + '/';
if (window.location.toString() === rootUrl) {
location.replace(`${window.location.href}data/?password=${document.getElementById("inputPassword").value}`);
} else {
location.replace(`${window.location.href}/data/?password=${document.getElementById("inputPassword").value}`);
};

}

</script>

</body>

</html>
</html>

0 comments on commit f80fe53

Please sign in to comment.