Configurable bind address, support for paths
This commit is contained in:
3
main.go
3
main.go
@@ -128,6 +128,7 @@ func main() {
|
|||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
keyFlag := flag.String("key", "", "secret key")
|
keyFlag := flag.String("key", "", "secret key")
|
||||||
|
bindFlag := flag.String("bind", ":2000", "host:port to listen on")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@@ -153,7 +154,7 @@ func main() {
|
|||||||
http.HandleFunc("/api/watch", watch)
|
http.HandleFunc("/api/watch", watch)
|
||||||
|
|
||||||
server := http.Server{
|
server := http.Server{
|
||||||
Addr: ":2000",
|
Addr: *bindFlag,
|
||||||
}
|
}
|
||||||
err := server.ListenAndServe()
|
err := server.ListenAndServe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ function renderRoom(roomId) {
|
|||||||
watch(roomId, clientId, adminSecret, prnt);
|
watch(roomId, clientId, adminSecret, prnt);
|
||||||
}
|
}
|
||||||
function newRoom() {
|
function newRoom() {
|
||||||
fetch("/api/create", { method: "POST" })
|
fetch("api/create", { method: "POST" })
|
||||||
.then(resp => resp.json())
|
.then(resp => resp.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const resp = data;
|
const resp = data;
|
||||||
@@ -43,7 +43,7 @@ function announce(roomId, clientId, adminSecret, name) {
|
|||||||
admin_secret: adminSecret,
|
admin_secret: adminSecret,
|
||||||
name: name.value,
|
name: name.value,
|
||||||
};
|
};
|
||||||
fetch("/api/announce", {
|
fetch("api/announce", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@@ -55,7 +55,7 @@ function announce(roomId, clientId, adminSecret, name) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
function watch(roomId, clientId, adminSecret, prnt) {
|
function watch(roomId, clientId, adminSecret, prnt) {
|
||||||
const url = new URL("/api/watch", location.href);
|
const url = new URL("api/watch", location.href);
|
||||||
url.searchParams.set("room_id", roomId);
|
url.searchParams.set("room_id", roomId);
|
||||||
url.searchParams.set("client_id", clientId);
|
url.searchParams.set("client_id", clientId);
|
||||||
if (adminSecret) {
|
if (adminSecret) {
|
||||||
@@ -127,7 +127,7 @@ function renderTimers(roomId, adminSecret, prnt, es) {
|
|||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
admin_secret: adminSecret,
|
admin_secret: adminSecret,
|
||||||
};
|
};
|
||||||
fetch("/api/reset", {
|
fetch("api/reset", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@@ -231,7 +231,7 @@ function active(roomId, adminSecret, publicClientId, val) {
|
|||||||
public_client_id: publicClientId,
|
public_client_id: publicClientId,
|
||||||
active: val,
|
active: val,
|
||||||
};
|
};
|
||||||
fetch("/api/active", {
|
fetch("api/active", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@@ -245,7 +245,7 @@ function admin(roomId, adminSecret, publicClientId) {
|
|||||||
admin_secret: adminSecret,
|
admin_secret: adminSecret,
|
||||||
public_client_id: publicClientId,
|
public_client_id: publicClientId,
|
||||||
};
|
};
|
||||||
fetch("/api/admin", {
|
fetch("api/admin", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@@ -262,7 +262,7 @@ function control(roomId, clientId, controls, ctrl) {
|
|||||||
client_id: clientId,
|
client_id: clientId,
|
||||||
control: ctrl,
|
control: ctrl,
|
||||||
};
|
};
|
||||||
fetch("/api/control", {
|
fetch("api/control", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
@@ -286,7 +286,7 @@ function remove(roomId, clientId) {
|
|||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
client_id: clientId,
|
client_id: clientId,
|
||||||
};
|
};
|
||||||
navigator.sendBeacon("/api/remove", JSON.stringify(req));
|
navigator.sendBeacon("api/remove", JSON.stringify(req));
|
||||||
}
|
}
|
||||||
function uuid() {
|
function uuid() {
|
||||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
||||||
|
|||||||
Reference in New Issue
Block a user