WIP: progress

This commit is contained in:
AJ ONeal 2019-06-22 01:28:02 -06:00
parent 6712864da0
commit 4c986119f9
2 changed files with 43 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
"strings"
"time" "time"
again "git.rootprojects.org/root/go-again" again "git.rootprojects.org/root/go-again"
@ -92,6 +93,13 @@ type scheduler struct {
} }
func (s *scheduler) Handle(w http.ResponseWriter, r *http.Request) { func (s *scheduler) Handle(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
token := strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")
if "" == token {
http.Error(w, "Authorization Header did not contain a valid token", http.StatusForbidden)
return
}
fmt.Println("whatever", r.Method, r.URL) fmt.Println("whatever", r.Method, r.URL)
switch r.Method { switch r.Method {
case http.MethodGet: case http.MethodGet:

View File

@ -5,5 +5,40 @@
</head> </head>
<body> <body>
<h1>Hello, World!</h1> <h1>Hello, World!</h1>
<form class="js-schedules-list">
<label
>Token:
<input class="js-auth-token" type="text" />
</label>
<button>See Schedules</button>
</form>
<pre><code class="js-schedules"> </code></pre>
<script>
'use strict';
document.body.addEventListener('submit', function(ev) {
if (ev.target.matches('.js-schedules-list')) {
ev.preventDefault();
ev.stopPropagation();
getSchedules();
}
});
function getSchedules() {
var token = document.querySelector('.js-auth-token').value;
window
.fetch('/api/schedules', {
headers: { Authorization: token }
})
.then(function(resp) {
return resp.json().then(function(schedules) {
document.querySelector(
'.js-schedules'
).innerText = JSON.stringify(schedules, null, 2);
});
});
return;
}
</script>
</body> </body>
</html> </html>