Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/webui/daemon-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import { randomBytes } from "crypto";
import express from "express";
import { loadChallengesIntoPKC } from "../challenge-packages/challenge-utils.js";

const rootHashRedirectScriptPattern =
/<script\b[^>]*>(?:(?!<\/script>)[\s\S])*?window\.location\.replace\(["']\/#["']\s*\+\s*window\.location\.pathname\s*\+\s*window\.location\.search\);(?:(?!<\/script>)[\s\S])*?<\/script>/;

async function _generateModifiedIndexHtmlWithRpcSettings(webuiPath: string, webuiName: string, ipfsGatewayPort: number) {
const indexHtmlString = (await fs.readFile(path.join(webuiPath, "index_backup_no_rpc.html")))
.toString()
.replace(/<script>\s*\/\/\s*Redirect non-hash URLs[\s\S]*?<\/script>/, "");
.replace(rootHashRedirectScriptPattern, "");
const defaultRpcOptionString = `[window.location.origin.replace("https://", "wss://").replace("http://", "ws://") + window.location.pathname.split('/' + '${webuiName}')[0]]`;
// Ipfs media only locally because ipfs gateway doesn't allow remote connections
const defaultIpfsMedia = `if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname === "0.0.0.0")window.defaultMediaIpfsGatewayUrl = 'http://' + window.location.hostname + ':' + ${ipfsGatewayPort}`;
Expand Down
6 changes: 4 additions & 2 deletions test/cli/daemon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,13 @@ describe(`bitsocial daemon webui`, async () => {
await stopPkcDaemon(daemonProcess);
});

it(`5chan webui does not contain the hash redirect script`, async () => {
it(`5chan webui does not contain the root hash redirect script`, async () => {
const res = await fetch(`http://localhost:${rpcUrl.port}/5chan`);
expect(res.status).toBe(200);
const html = await res.text();
expect(html).not.toMatch(/Redirect non-hash URLs/);
expect(html).not.toMatch(
/window\.location\.replace\(["']\/#["']\s*\+\s*window\.location\.pathname\s*\+\s*window\.location\.search\)/
);
});

it(`POST /api/challenges/reload returns 200 for local connections`, async () => {
Expand Down
Loading