defining address and enabling sse and wss

main
alex 2023-01-08 20:47:22 +01:00
parent cffd651965
commit cb75d9630f
3 changed files with 93 additions and 3 deletions

View File

@ -5,6 +5,8 @@ import {fetchToken, onMessageListener} from './firebase'
function App() {
fetchToken();
test()
onMessageListener().then(payload => {
console.log(payload);
}).catch(err => console.log('failed: ', err));
@ -30,3 +32,16 @@ function App() {
}
export default App;
function test() {
console.log("test")
fetch("http://localhost:8080/v1/users/06666445-b110-48aa-bb7b-36a379e6ae05", {
method: "GET",
headers: {
"X-AUTHORizatioN": "testa"
}
})
.then((response) => response.json())
.then((data) => console.log(data))
}

64
picture-upload.html Normal file
View File

@ -0,0 +1,64 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
background-color: black;
color: white;
}
</style>
</head>
<body>
<label>Select image to upload</label>
<input type="file" name="myFile" id="fileinput">
<br><br>
<span id="res-url">Upload file to see url</span>
<button id="btn-open">Open in new tab</button>
<script>
//const url = "http://localhost:8081/v1/user/avatar"
const url = "https://alpha-storage.clickandjoin.umbach.dev/v1/user/avatar"
const input = document.getElementById("fileinput")
const upload = (file) => {
const data = new FormData()
data.append("file", file)
fetch(url,{
method: "POST",
headers: {
"X-Authorization": "SpebbxEG-gOTn-C7z6-SvO3-UCtv9ZRleg3r"
},
body: data
})
.then(res => res.text())
.then(succ => {
console.log(succ)
let json = JSON.parse(succ)
document.getElementById("res-url").innerHTML = json["AvatarUrl"]
window.open(document.getElementById("res-url").innerHTML, "_blank")
})
.catch(err => console.log(err))
}
const onSelectFile = () => upload(input.files[0])
input.addEventListener("change", onSelectFile, false)
document.getElementById("btn-open").onclick = () => {
window.open(document.getElementById("res-url").innerHTML, "_blank")
}
</script>
</body>
</html>

View File

@ -1,7 +1,14 @@
let ws = null
let wsAddress = "ws://localhost:"
let wsPort = 3000
let wsAddress = "ws://localhost:"
//let wsAddress = "wss://alpha-ws.clickandjoin.umbach.dev"
let sseAddress = "http://127.0.0.1:3005/"
//let sseAddress = "https://alpha-sse.clickandjoin.umbach.dev/"
const sseEnabled = true
const wssEnabled = true
window.onload = () => {
const msg = document.getElementById("msg")
@ -41,12 +48,14 @@ window.onload = () => {
}
connectWS()
//connectSSE()
connectSSE()
}
function connectSSE() {
var source = new EventSource("http://127.0.0.1:3005/sse")
if (!sseEnabled) return
var source = new EventSource(sseAddress)
source.onmessage = (e) => {
console.log(e.data)
@ -57,6 +66,8 @@ function connectSSE() {
}
function connectWS() {
if (!wssEnabled) return
ws = new WebSocket(wsAddress + wsPort + "/?auth=sMURqnQt-88Ko-SaWu-2GLr-K2iQECXDyONm")
ws.onopen = () => {