rust server working :) !!!

This commit is contained in:
unurled 2023-02-16 13:30:06 +01:00
parent d625ced9b1
commit e00ab6183c
33 changed files with 410 additions and 1159 deletions

17
public/css/main.css Normal file
View file

@ -0,0 +1,17 @@
#content {
position: absolute;
top: 40vh;
}
#login-content {
position: absolute;
top: 20vh;
}
#login {
bottom: 5vh;
}
#text {
font-size: large;
}

31
public/edit.html Normal file
View file

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Text Display</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link href="css/main.css" rel="stylesheet">
</head>
<body>
<script src="js/edit.js"></script>
<div id="login-content" class="container-fluid text-center">
<div class="container">
<h1>Login</h1>
<div class="container">
<div class="form-floating">
<textarea class="form-control" placeholder="Text" id="text" style="height: 50vh;"></textarea>
<label for="text">Set your text</label>
</div>
<br>
<input class="btn btn-primary" type="submit" value="Save" onclick="saveText()">
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<script src="js/main.js"></script>
</body>
</html>

23
public/index.html Normal file
View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Text Display</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link href="css/main.css" rel="stylesheet">
</head>
<body>
<div id="content" class="container-fluid text-center">
<div class="container">
<p id="text"></p>
</div>
<div id="login" class="container fixed-bottom">
<a class="btn btn-outline-info login-btn" href="login.html">Login</a>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<script src="js/main.js"></script>
</body>
</html>

17
public/js/edit.js Normal file
View file

@ -0,0 +1,17 @@
function saveText() {
let x = document.getElementById("text").value;
const options = {method: 'POST', body: JSON.stringify({text: x}), headers: { 'Content-Type': 'application/json' }};
fetch('http://127.0.0.1:8000/api/edit', options)
.then((response) => response.text())
.then(data => {
redirectOrNot(data);
})
.catch(err => console.error(err));
}
async function redirectOrNot(res) {
let url = "http://" + location.hostname + ":" + location.port
location.href = url+res
}

17
public/js/login.js Normal file
View file

@ -0,0 +1,17 @@
function formLink() {
let x = document.getElementById("Token").value;
const options = {method: 'POST', headers: {Token: x}};
fetch('http://127.0.0.1:8000/login', options)
.then((response) => response.text())
.then(data => {
redirectOrNot(data);
})
.catch(err => console.log(err));
}
async function redirectOrNot(res) {
let url = "http://" + location.hostname + ":" + location.port
location.href = url+res
}

18
public/js/main.js Normal file
View file

@ -0,0 +1,18 @@
!async function(){
let data = await fetch("http://localhost:8000/api")
.then((response) => response.text())
.then(data => {
return data;
})
.catch(error => {
console.error(error);
});
console.log(data);
print(data);
}();
function print(data) {
document.getElementById("text").innerText = data
document.getElementById("text").value = data
}

30
public/login.html Normal file
View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Text Display</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link href="css/main.css" rel="stylesheet">
</head>
<body>
<script src="js/login.js"></script>
<div id="login-content" class="container-fluid text-center">
<div class="container">
<h1>Login</h1>
<div class="container">
<div class="input-group">
<label class="input-group-text">Api - key</label>
<input name="Token" id="Token" type="text" class="form-control" placeholder="xxxx-xxxx-xxxxx-xxxxx">
</div>
<br>
<input class="btn btn-primary" type="submit" value="Submit" onclick="formLink()">
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>