replay: install RWP files directly into image on build, instead of loading from cdn during crawl time

This commit is contained in:
Ilya Kreymer 2024-02-21 08:48:48 -08:00
parent bad67a014a
commit 3617bb6c0b
3 changed files with 19 additions and 10 deletions

View file

@ -47,6 +47,10 @@ ADD config/ /app/
ADD html/ /app/html/
ARG RWP_VERSION=1.8.14
ADD https://cdn.jsdelivr.net/npm/replaywebpage@${RWP_VERSION}/ui.js /app/html/rwp/
ADD https://cdn.jsdelivr.net/npm/replaywebpage@${RWP_VERSION}/sw.js /app/html/rwp/
RUN chmod u+x /app/dist/main.js /app/dist/create-login-profile.js
RUN ln -s /app/dist/main.js /usr/bin/crawl; \

View file

@ -1,7 +1,7 @@
<!doctype html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/replaywebpage@$RWP_VERSION/ui.js"></script>
<script src="/ui.js"></script>
<style>
html {
width: 100%;

View file

@ -3,14 +3,18 @@ import fsp from "fs/promises";
import http, { IncomingMessage, ServerResponse } from "http";
import path from "path";
const RWP_VERSION = "1.8.14";
const replayHTML = fs.readFileSync(
new URL("../../html/replay.html", import.meta.url),
{ encoding: "utf8" },
);
const swJS = `importScripts("https://cdn.jsdelivr.net/npm/replaywebpage@${RWP_VERSION}/sw.js");`;
const swJS = fs.readFileSync(new URL("../../html/rwp/sw.js", import.meta.url), {
encoding: "utf8",
});
const uiJS = fs.readFileSync(new URL("../../html/rwp/ui.js", import.meta.url), {
encoding: "utf8",
});
// ============================================================================
const PORT = 9990;
@ -68,11 +72,7 @@ export class ReplayServer {
switch (pathname) {
case "/":
response.writeHead(200, { "Content-Type": "text/html" });
response.end(
replayHTML
.replace("$SOURCE", this.sourceUrl)
.replace("$RWP_VERSION", RWP_VERSION),
);
response.end(replayHTML.replace("$SOURCE", this.sourceUrl));
return;
case "/sw.js":
@ -83,6 +83,11 @@ export class ReplayServer {
response.end(swJS);
return;
case "/ui.js":
response.writeHead(200, { "Content-Type": "application/javascript" });
response.end(uiJS);
return;
case this.sourceUrl:
if (this.sourceContentType && this.origFileSource) {
if (!this.sourceSize) {
@ -97,7 +102,7 @@ export class ReplayServer {
"Content-Length": contentLength,
"Content-Range": contentRange,
});
console.log(request.method, contentRange, opts);
//console.log(request.method, contentRange, opts);
if (request.method === "GET") {
fs.createReadStream(this.origFileSource, opts).pipe(response);
} else {