mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 23:49:44 +08:00
Make UI independent of URI
This commit is contained in:
parent
68a45adac7
commit
82faa2e9c9
File diff suppressed because it is too large
Load Diff
@ -72,7 +72,7 @@ const Login = function(props) {
|
|||||||
const [pass, setPass] = useState('');
|
const [pass, setPass] = useState('');
|
||||||
const login = ev =>
|
const login = ev =>
|
||||||
fetch(
|
fetch(
|
||||||
'/api/login',
|
'api/login',
|
||||||
{headers: {Authorization: 'Basic ' + btoa(user + ':' + pass)}})
|
{headers: {Authorization: 'Basic ' + btoa(user + ':' + pass)}})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(r => r && props.login(r))
|
.then(r => r && props.login(r))
|
||||||
@ -113,7 +113,7 @@ const Configuration = function(props) {
|
|||||||
setSub(props.config.sub);
|
setSub(props.config.sub);
|
||||||
}, [props.config]);
|
}, [props.config]);
|
||||||
|
|
||||||
const update = (name, val) => fetch('/api/config/set', {
|
const update = (name, val) => fetch('api/config/set', {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
body: `${name}=${encodeURIComponent(val)}`
|
body: `${name}=${encodeURIComponent(val)}`
|
||||||
}).catch(err => err);
|
}).catch(err => err);
|
||||||
@ -184,7 +184,7 @@ const Messages = function(props) {
|
|||||||
return PubSub.unsubscribe(id);
|
return PubSub.unsubscribe(id);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const sendmessage = ev => fetch('/api/message/send', {
|
const sendmessage = ev => fetch('api/message/send', {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
body: `message=${encodeURIComponent(txt)}`
|
body: `message=${encodeURIComponent(txt)}`
|
||||||
}).then(r => setTxt(''));
|
}).then(r => setTxt(''));
|
||||||
@ -310,7 +310,7 @@ const App = function(props) {
|
|||||||
const [config, setConfig] = useState({});
|
const [config, setConfig] = useState({});
|
||||||
|
|
||||||
const getconfig = () =>
|
const getconfig = () =>
|
||||||
fetch('/api/config/get', {headers: {Authorization: ''}})
|
fetch('api/config/get', {headers: {Authorization: ''}})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(r => setConfig(r))
|
.then(r => setConfig(r))
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
@ -319,7 +319,7 @@ const App = function(props) {
|
|||||||
// to all subscribed components
|
// to all subscribed components
|
||||||
const watch = function() {
|
const watch = function() {
|
||||||
var l = window.location, proto = l.protocol.replace('http', 'ws');
|
var l = window.location, proto = l.protocol.replace('http', 'ws');
|
||||||
var tid, wsURI = proto + '//' + l.host + '/api/watch'
|
var tid, wsURI = proto + '//' + l.host + l.pathname + 'api/watch'
|
||||||
var reconnect = function() {
|
var reconnect = function() {
|
||||||
var ws = new WebSocket(wsURI);
|
var ws = new WebSocket(wsURI);
|
||||||
// ws.onopen = () => console.log('ws connected');
|
// ws.onopen = () => console.log('ws connected');
|
||||||
@ -360,7 +360,7 @@ const App = function(props) {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Called once at init time
|
// Called once at init time
|
||||||
PubSub.subscribe(msg => msg.name == 'config' && getconfig());
|
PubSub.subscribe(msg => msg.name == 'config' && getconfig());
|
||||||
fetch('/api/login', {headers: {Authorization: ''}})
|
fetch('api/login', {headers: {Authorization: ''}})
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.then(r => login(r))
|
.then(r => login(r))
|
||||||
.catch(err => setUser(''));
|
.catch(err => setUser(''));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user