Skip to content

Commit

Permalink
embed.jsをサーバーから提供
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Jun 25, 2024
1 parent 1b6216d commit e88fc36
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/backend/assets/embed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: MIT
*/
//@ts-check
(() => {
/** @type {NodeListOf<HTMLIFrameElement>} */
const els = document.querySelectorAll('iframe[data-misskey-embed-id]');

window.addEventListener('message', function (event) {
els.forEach((el) => {
if (event.source !== el.contentWindow) {
return;
}

const id = el.dataset.misskeyEmbedId;

if (event.data.type === 'misskey:embed:ready') {
el.contentWindow?.postMessage({
type: 'misskey:embedParent:registerIframeId',
payload: {
iframeId: id,
}
}, '*');
}
if (event.data.type === 'misskey:embed:changeHeight' && event.data.iframeId === id) {
el.style.height = event.data.payload.height + 'px';
}
});
});
})();
7 changes: 7 additions & 0 deletions packages/backend/src/server/web/ClientServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,13 @@ export class ClientServerService {
// Manifest
fastify.get('/manifest.json', async (request, reply) => await this.manifestHandler(reply));

// Embed Javascript
fastify.get('/embed.js', async (request, reply) => {
return await reply.sendFile('/embed.js', staticAssets, {
maxAge: ms('1 day'),
});
});

fastify.get('/robots.txt', async (request, reply) => {
return await reply.sendFile('/robots.txt', staticAssets);
});
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/vite.config.local-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const devConfig = {
ws: true,
},
'/favicon.ico': httpUrl,
'/robots.txt': httpUrl,
'/embed.js': httpUrl,
'/identicon': {
target: httpUrl,
rewrite(path) {
Expand Down

0 comments on commit e88fc36

Please sign in to comment.