Front end application for Digital Research Books, based on NYPL's Reservoir Design System.
Provides a "Welcome page" entry point with heading, search box, and tagline. Connects to an ElasticSearch index via an API endpoint (https://digital-research-books-api.nypl.org). Simple searches can be entered in the form and an index response is displayed back to the user.
- Technical Overview
- Getting Started
- Running the App
- Local Hosting
- Running with Docker
- Testing
- Using the App
- EPUB to Webpub
- C4 Architecture Diagrams
- Deployment
- Node.js
- Next.js (bootstrapped with
create-next-app) - NYPL Design System
- NYPL Web Reader
The following steps set up the application to run locally.
📂 Run all commands below from the
webfolder of the repository unless specfied otherwise.
This app currently runs on Node.js v22.
First check if it is already installed by running:
node -v
If the returned version looks something like v22.xx.x and/or it matches the major version specified in .nvmrc, then proceed to the next step.
If a different version is returned, install the Node version used by the app with:
nvm install
However if an error message is returned stating that the command cannot be found, then Node must be installed. The easiest way to do this is with a version manager like nvm.
Check if nvm is installed with:
nvm -v
If that command is not found, install it with:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
After verifying a successfull installation, run nvm install to install the expected version.
Alternatively, download and install the expected Node version from the official site.
Install dependencies with:
npm install
Note: Adding --production to the command installs only production dependencies however be aware that the prod build also runs linting and type checks that rely on development dependencies such as eslint and jest. To help avoid build errors due to missing packages, it's recommended to install all dependencies.
Set up an environment file to store configuration variables and secrets:
- Create a new file named
.envin thewebfolder. - Copy the contents of
.env.sampleinto.env. - Obtain required secrets from the development team and add them to your environment file as intended.
🔐 There are tests that depend on setting user credentials for accessing the catalog and VRA.
To view PDFs locally through the webreader, set up a local proxy as described in its instructions.
To start the application locally at localhost:3000:
For development:
npm run dev
For production:
npm run build
npm start
For consistent code formatting and linting, please install these VS Code extensions:
Auto-formatting and linting on save are enabled via workspace settings.
If you have issues, check that these extensions are enabled and up to date.
To successfully log in under a local deployment, add the following line to your machine's /etc/hosts file:
127.0.0.1 local.nypl.org
This is necessary because NYPL's authentication system works by reading cookies and parsing the patron's encrypted credentials. These cookies only work on .nypl.org domains, so we need to map our local deployment to a .nypl.org domain
To run the application with Docker:
- Download and install Docker.
cdinto thewebdirectory.- Build and run the application with
docker compose up.
The app will be served at http://localhost:3000
Run tests in a separate terminal from the app using the commands below.
npm run test
E2E tests for this application are powered by Playwright.
Playwright gets installed with the rest of the application's dependencies when npm install is run.
To verify Playwright is installed, run:
npx playwright --version
If no version number is returned, install Playwright manually:
npm install playwright
ℹ️ Manual installation may be required if only production dependencies are installed (as in playwright.yml).
Download the browser binaries and their required dependencies with:
npx playwright install --with-deps
To run the entire test suite:
npm run playwright
To run tests in specific file:
npm run playwright /path/to/file
Various command line arguments can be used to customize test runs. Common examples are given below. See the Playwright docs for more.
Playwright tests run in headless browsers by default. To see them run in actual browsers, use the
--headedoption:npm run playwright -- --headedSince Playwright runs tests in parallel across multiple browsers by default, it's recommended combining this option with
--workers=1to contain them to a single browser instance.Access interactive tools for enhanced debugging by using the
--uioption:npm run playwright -- --uiRun only the tests that failed in the most recent run with the
--last-failedoption:npm run playwright -- --last-failed
Currently takes in a query string to pass along to the ResearchNow Search API which submits a keyword search to the Elasticsearch instance, and renders the returned output. Sends the query parameter specified in the rendered search form on the main page.
Search via keyword, author, title, subject have been implemented. Terms use the AND boolean operator by default. Search terms can also use the OR boolean operator and search terms can be quoted for phrase searching. Combinations of these can be used as well for more complex searching using the basic search input.
Term combinations
- One term: jefferson
- Multiple terms: world war
- Phrase: "English Literature"
- Single term and phrase: james AND "English Literature"
These types of combinations can be used with any available field selection.
Search Results can be filtered by year range, language and available format.
Advanced Search works like the Simple Search, but allows searching for multiple fields and for pre-filtering. Terms use the AND boolean operator.
Example: Subject:"English Literature" AND Keyword:"Witches"
- Each source record is represented as an Item (something that can actually be read online), which are grouped into Editions (e.g. the 1917 edition of X), which are in turn grouped into Works, (e.g. Moby Dick, or, The Whale). Through this a user can search for and find a single Work record and see all editions of that Work and all of its options for reading online.
- The information and code for this normalization is found in the drb-etl-pipeline repo
Books can be read three ways:
- Embedded page: DRB embeds a read-online page from a different source. DRB commonly does this for Hathitrust books
- Webpub reader: DRB serves an epub through the webpub-viewer. DRB commonly does this for Gutenberg Project books.
- Download: DRB offers a link to download the book online. This is often done for PDFs.
The EPUB to Webpub Next.js app is deployed at https://epub-to-webpub.vercel.app. The /api/[containerXmlUrl] endpoint is used by the DRB backend to convert container.xml files of exploded EPUBs to webpub manifests.
See Structurizr link and update via the c4-diagrams repo.
Continuous deployment and integration is implemented via GitHub Actions when changes are merged to main.