Skip to content

Commit b69e3a6

Browse files
authored
Added rootDir option to renderCalderaApp (#10)
This commit creates a new option on the `renderCalederaApp` function allowing users to set their own public directory. This allows customization of the template, CSS, scripts, etc... This change keeps the caledera-client.js being served from the Caledera root directory.
1 parent 846c916 commit b69e3a6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Diff for: src/server/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export type Dispatch = (
3030

3131
export const renderCalderaApp = (
3232
app: React.ReactElement,
33-
options: { port?: number; hostname?: string } = {}
33+
options: { port?: number; hostname?: string; rootDir?: string; } = {}
3434
) => {
3535
const savedStates = new Map<SessionID, Buffer>();
3636
const server = http.createServer((req, res) =>
37-
serve(req, res, finalhandler(req, res))
37+
serve(req, res, finalhandler(req, res), options)
3838
);
3939
const wss = new WebSocket.Server({
4040
noServer: true,

Diff for: src/server/serve.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ import { IncomingMessage, ServerResponse } from "http";
22
import path from "path";
33
import fs from "fs";
44

5-
const rootDir = path.resolve(__dirname, "..", "public");
5+
const calderaRootDir = path.resolve(__dirname, "..", "public");
66

77
const serve = (
88
req: IncomingMessage,
99
res: ServerResponse,
10-
onError: (err: any) => void
10+
onError: (err: any) => void,
11+
options: { rootDir?: string; } = {}
1112
) => {
13+
let rootDir = (options.rootDir ? options.rootDir : calderaRootDir);
14+
1215
const url = req.url;
1316

1417
let filePath = "index.html";
1518
let mimeType = "text/html";
1619

1720
if (url === "/caldera-client.js") {
1821
filePath = url.slice(1);
22+
rootDir = calderaRootDir;
1923
mimeType = "application/javascript";
2024
}
2125

0 commit comments

Comments
 (0)