Skip to content

Commit

Permalink
fix: Don't add index logic to StaticSandbox (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeMoorJasper authored Apr 3, 2023
1 parent 053455f commit 146287b
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions sandpack-client/src/clients/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import type { SandpackNodeMessage } from "../node/types";

import { insertHtmlAfterRegex, readBuffer, writeBuffer } from "./utils";

const INDEX_FILENAMES = ["index.html", "index.htm"];

export class SandpackStatic extends SandpackClient {
private emitter: EventEmitter;
private previewController: PreviewController;
Expand All @@ -41,19 +39,12 @@ export class SandpackStatic extends SandpackClient {
// filepath is always normalized to start with / and not end with a slash
getFileContent: (filepath) => {
let content = this.files.get(filepath);

if (!content) {
content = this.getIndexContent(filepath);
throw new Error("File not found");
}
const isHTMLFilePath =
filepath.endsWith(".html") ||
filepath.endsWith(".htm") ||
filepath.endsWith("/");

if (isHTMLFilePath) {
if (filepath.endsWith(".html") || filepath.endsWith(".htm")) {
content = this.injectProtocolScript(content);
}

return content;
},
});
Expand Down Expand Up @@ -106,22 +97,6 @@ export class SandpackStatic extends SandpackClient {
return writeBuffer(content);
}

private getIndexContent(filepath: string): string | Uint8Array {
const rootDir = filepath === "/" ? filepath : filepath + "/";
for (const indexFilename of INDEX_FILENAMES) {
const fullPath = rootDir + indexFilename;
const foundFile = this.files.get(fullPath);
if (foundFile) {
return foundFile;
}
}
if (rootDir === "/") {
return "<div>File not found</div>";
} else {
return this.getIndexContent("/");
}
}

public updateSandbox(
setup = this.sandboxSetup,
_isInitializationCompile?: boolean
Expand Down

1 comment on commit 146287b

@vercel
Copy link

@vercel vercel bot commented on 146287b Apr 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

sandpack-docs – ./website/docs

sandpack-docs-codesandbox1.vercel.app
sandpack-docs-git-main-codesandbox1.vercel.app
sandpack.vercel.app

Please sign in to comment.