Updated message handler for dynamic admin urls

refs https://github.com/TryGhost/Team/issues/1664
This commit is contained in:
Simon Backx 2022-07-08 11:17:54 +02:00 committed by Simon Backx
parent a6842e8a20
commit e1a3adea6a

View File

@ -1,3 +1,5 @@
const adminUrl = window.location.href.replace('auth-frame/', '');
window.addEventListener('message', async function (event) {
if (event.origin !== '*') {
// return;
@ -20,7 +22,7 @@ window.addEventListener('message', async function (event) {
if (data.action === 'getUser') {
try {
const res = await fetch(
'https://admin.egg/blog/ghost/api/canary/admin/users/me/'
adminUrl + 'api/canary/admin/users/me/'
);
const json = await res.json();
respond(null, json);
@ -31,7 +33,7 @@ window.addEventListener('message', async function (event) {
if (data.action === 'hideComment') {
try {
const res = await fetch('https://admin.egg/blog/ghost/api/canary/admin/comments/' + data.id + '/', {
const res = await fetch(adminUrl + 'api/canary/admin/comments/' + data.id + '/', {
method: 'PUT',
body: JSON.stringify({
comments: [{
@ -52,7 +54,7 @@ window.addEventListener('message', async function (event) {
if (data.action === 'showComment') {
try {
const res = await fetch('https://admin.egg/blog/ghost/api/canary/admin/comments/' + data.id + '/', {
const res = await fetch(adminUrl + 'api/canary/admin/comments/' + data.id + '/', {
method: 'PUT',
body: JSON.stringify({
comments: [{