add messages api

This commit is contained in:
kandrusyak
2022-10-05 16:42:19 +03:00
parent 2210b4ab91
commit e07353cd87
2 changed files with 16 additions and 11 deletions

View File

@@ -5,10 +5,12 @@ import { HashRouter as Router } from 'react-router-dom'
import App from './App' import App from './App'
import {store} from './store/store'; import {store} from './store/store';
import './utils/messagesApi' import { allowMessages } from './utils/messagesApi'
globalThis.Buffer = Buffer globalThis.Buffer = Buffer
allowMessages();
window.store = store; window.store = store;
BigInt.prototype.toJSON = function() { BigInt.prototype.toJSON = function() {

View File

@@ -1,12 +1,15 @@
const domains = [ export const allowMessages = () => {
"http://dev.kandrusyak.ru", const domains = [
] "http://dev.kandrusyak.ru",
window.addEventListener("message", messageHandler, false); ]
function messageHandler(event) { window.addEventListener("message", messageHandler, false);
if (!domains.includes(event.origin))
return; function messageHandler(event) {
const { action, key, value } = event.data if (!domains.includes(event.origin))
if (action === 'save'){ return;
window.localStorage.setItem(key, JSON.stringify(value)) const {action, key, value} = event.data
if (action === 'save') {
window.localStorage.setItem(key, JSON.stringify(value))
}
} }
} }