Skip to content

Use custom live server to handle BR url mode history#1509

Open
cdrini wants to merge 2 commits intointernetarchive:masterfrom
cdrini:feature/urlmode-history-demo
Open

Use custom live server to handle BR url mode history#1509
cdrini wants to merge 2 commits intointernetarchive:masterfrom
cdrini:feature/urlmode-history-demo

Conversation

@cdrini
Copy link
Contributor

@cdrini cdrini commented Feb 4, 2026

Adds a new demo option for url mode history, with support for things like /details/<ocaid>/page/3. You just start the npm run serve-dev server as usual, and select the demo for url mode history. Note this will work locally and on netlify, eg https://deploy-preview-1509--ia-bookreader.netlify.app/details/adventureofsherl0000unse/mode/2up?q=sleep

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.70%. Comparing base (5c571e0) to head (16131c0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1509   +/-   ##
=======================================
  Coverage   69.70%   69.70%           
=======================================
  Files          65       65           
  Lines        5373     5373           
  Branches     1182     1182           
=======================================
  Hits         3745     3745           
  Misses       1594     1594           
  Partials       34       34           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for URL history mode in BookReader demos by implementing a custom live-server with middleware that rewrites /details/<identifier> URLs to the demo page. This allows testing the Internet Archive's URL pattern (/details/<ocaid>/page/3) locally.

Changes:

  • Added custom live-server script with middleware to rewrite /details/<identifier> requests
  • Updated serve-live npm script to use the custom server
  • Modified demo-internetarchive.html to use absolute paths and added logic to detect details page URLs
  • Added new demo link in index.html showcasing the history URL mode

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
scripts/live-server.js New middleware-based live server that rewrites /details/ URLs to demo page
package.json Updated serve-live script to use custom server
index.html Added demo link for history mode and removed obsolete comments
BookReaderDemo/demo-internetarchive.html Changed to absolute paths for compatibility with URL rewriting
BookReaderDemo/IADemoBr.js Added logic to detect details URLs, extract ocaid, rewrite links, and configure history mode

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

console.log(`${req.method} ${req.url}`);

// Handle /details/<identifier> requests
const detailsMatch = req.url.match(/^\/details\/([^/?]+)/);
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The regex pattern /^\/details\/([^/?]+)/ captures the identifier but doesn't use the captured group. While the code correctly rewrites to the demo page (which will extract the identifier from the path), consider removing the capturing group if it's not being used, or store it for potential future use or logging.

Suggested change
const detailsMatch = req.url.match(/^\/details\/([^/?]+)/);
const detailsMatch = req.url.match(/^\/details\/[^/?]+/);

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +36
<script src="/BookReader/webcomponents-bundle.js"></script>
<script src="/BookReader/jquery-3.js"></script>

<!-- Bookreader -->
<script src="../BookReader/BookReader.js"></script>
<link rel="stylesheet" href="../BookReader/BookReader.css"/>
<script src="/BookReader/BookReader.js"></script>
<link rel="stylesheet" href="/BookReader/BookReader.css"/>

<!-- plugins needed for archive.org, in same order as archive.org -->
<script src="../BookReader/plugins/plugin.search.js"></script>
<script src="../BookReader/plugins/plugin.chapters.js"></script>
<script src="../BookReader/plugins/plugin.tts.js"></script>
<script src="../BookReader/plugins/plugin.url.js"></script>
<script src="../BookReader/plugins/plugin.autoplay.js"></script>
<script src="../BookReader/plugins/plugin.resume.js"></script>
<script src="../BookReader/plugins/plugin.archive_analytics.js"></script>
<script src="../BookReader/plugins/plugin.text_selection.js"></script>
<script src="../BookReader/plugins/plugin.experiments.js"></script>
<script src="/BookReader/plugins/plugin.search.js"></script>
<script src="/BookReader/plugins/plugin.chapters.js"></script>
<script src="/BookReader/plugins/plugin.tts.js"></script>
<script src="/BookReader/plugins/plugin.url.js"></script>
<script src="/BookReader/plugins/plugin.autoplay.js"></script>
<script src="/BookReader/plugins/plugin.resume.js"></script>
<script src="/BookReader/plugins/plugin.archive_analytics.js"></script>
<script src="/BookReader/plugins/plugin.text_selection.js"></script>
<script src="/BookReader/plugins/plugin.experiments.js"></script>

<script type="module" src="../BookReader/ia-bookreader-bundle.js"></script>
<script type="module" src="/BookReader/ia-bookreader-bundle.js"></script>

<link rel="stylesheet" href="BookReaderDemo.css"/>
<link rel="stylesheet" href="/BookReaderDemo/BookReaderDemo.css"/>
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

Changing from relative paths (../BookReader) to absolute paths (/BookReader) creates a deviation from all other demo files and makes this demo only work when served from the root path through the live-server middleware. If someone tries to access this file directly via file:// protocol or from a different path, the absolute paths will fail. Consider documenting this requirement or maintaining relative paths and handling path resolution differently.

Copilot uses AI. Check for mistakes.
"lint:fix": "npx eslint --fix src/ tests/ *.js *.cjs",
"serve": "npx http-server . --port=8000",
"serve-live": "npx live-server . --cors --port=8000 --watch=index.html,BookReader,BookReaderDemo",
"serve-live": "node scripts/live-server.js",
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The e2e test helper in tests/e2e/helpers/params.js uses logic to determine whether to use /details/ URLs (for archive.org) or /BookReaderDemo/demo-internetarchive.html URLs (for demos). With this PR adding support for /details/ URLs in the demo environment, consider updating the test helper to support this new route when testing locally, or documenting that tests should continue to use the query parameter approach.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants