defining address and enabling sse and wss
parent
cffd651965
commit
cb75d9630f
|
@ -5,6 +5,8 @@ import {fetchToken, onMessageListener} from './firebase'
|
||||||
function App() {
|
function App() {
|
||||||
fetchToken();
|
fetchToken();
|
||||||
|
|
||||||
|
test()
|
||||||
|
|
||||||
onMessageListener().then(payload => {
|
onMessageListener().then(payload => {
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
}).catch(err => console.log('failed: ', err));
|
}).catch(err => console.log('failed: ', err));
|
||||||
|
@ -30,3 +32,16 @@ function App() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default 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))
|
||||||
|
}
|
|
@ -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>
|
17
script.js
17
script.js
|
@ -1,7 +1,14 @@
|
||||||
let ws = null
|
let ws = null
|
||||||
|
|
||||||
let wsAddress = "ws://localhost:"
|
|
||||||
let wsPort = 3000
|
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 = () => {
|
window.onload = () => {
|
||||||
const msg = document.getElementById("msg")
|
const msg = document.getElementById("msg")
|
||||||
|
@ -41,11 +48,13 @@ window.onload = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
connectWS()
|
connectWS()
|
||||||
//connectSSE()
|
connectSSE()
|
||||||
}
|
}
|
||||||
|
|
||||||
function 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) => {
|
source.onmessage = (e) => {
|
||||||
console.log(e.data)
|
console.log(e.data)
|
||||||
|
@ -57,6 +66,8 @@ function connectSSE() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function connectWS() {
|
function connectWS() {
|
||||||
|
if (!wssEnabled) return
|
||||||
|
|
||||||
ws = new WebSocket(wsAddress + wsPort + "/?auth=sMURqnQt-88Ko-SaWu-2GLr-K2iQECXDyONm")
|
ws = new WebSocket(wsAddress + wsPort + "/?auth=sMURqnQt-88Ko-SaWu-2GLr-K2iQECXDyONm")
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
|
|
Loading…
Reference in New Issue