Skip to content

Commit

Permalink
app in app problem resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
victazzz committed Feb 7, 2025
1 parent 1c56a46 commit c747998
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineConfig({
* @doc https://umijs.org/docs/api/config#hash
*/
hash: true,

base: '/',
history: { type: 'browser' },

/**
Expand Down Expand Up @@ -159,4 +159,5 @@ export default defineConfig({
typeof REACT_APP_SENTRY_RELEASE !== 'undefined' ? REACT_APP_SENTRY_RELEASE : '',
},
devtool: 'source-map',
plugins: [require.resolve('./plugin-scorm.ts')],
});
14 changes: 14 additions & 0 deletions config/plugin-scorm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { IApi } from 'umi';

export default (api: IApi) => {
api.addBeforeMiddlewares(() => [
(req, res, next) => {
if (req.url.startsWith('/courses/scorms/preview/__scorm__/')) {
res.statusCode = 404;
res.end('Not found (blocked by scormIntercept plugin)');
return;
}
next();
},
]);
};
8 changes: 4 additions & 4 deletions public/service-worker-scorm.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ self.addEventListener("message", async (event) => {

// Fetching content using Service Worker
self.addEventListener("fetch", async (e) => {

if (e.request.url.includes(FOLDER_PREFIX)) {
const id = e.request.url.split(FOLDER_PREFIX)[1].split("/").join("");
const zip = resolvers[id];

// find zip ID
if (zip) {
const uri = e.request.url.split(FOLDER_PREFIX)[2].substr(1).split("?")[0];
const ext = uri.split(".").pop();
console.log({ext})

const mime = Mimes[ext];
console.log(mime)

if (zip.files[uri]) {
console.log(zip.files[uri], zip.files, uri);

e.respondWith(
(async () => {
const responseBody = await zip.file(uri).async("blob");
Expand Down
3 changes: 2 additions & 1 deletion src/components/Scorm/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ScormPreview: React.FC<{ uuid: string }> = ({ uuid }) => {
url: string = '/service-worker-scorm.js',
): Promise<ServiceWorkerRegistration | null> => {
try {
const registration = await navigator.serviceWorker.register(url);
const registration = await navigator.serviceWorker.register(url, { scope: '/' });
if (registration.active) {
return registration;
}
Expand Down Expand Up @@ -175,6 +175,7 @@ const ScormPreview: React.FC<{ uuid: string }> = ({ uuid }) => {
// 5) Double-check the file is actually served (avoid “app in app”).
try {
const headCheck = await fetch(potentialIframeUrl, { method: 'HEAD' });
console.log({ headCheck });
if (!headCheck.ok) {
throw new Error(`SCORM entry file missing: ${headCheck.status}`);
}
Expand Down

0 comments on commit c747998

Please sign in to comment.