The serve command is designed to stream and parse packaged publications and serve them as Web Publications over HTTP/HTTPS.
By default, this command will serve publications available in a given directory from the filesystem.
Since there's no default path, it requires the presence of a --file-directory flag and a path.
-
Serving files from a directory.
readium serve --file-directory ./publications
For debugging purposes, the server exposes a /list.json endpoint that
returns a list of all the publications found in the directory along with their
encoded paths.
This will be replaced by an OPDS 2.0 feed in a future release, using an optional flag.
Many services provide an S3 compatible API. The serve command is fully compatible with these API, allowing implementers to stream and serve publications stored in multiple buckets.
-
Streaming files from an S3 compatible API.
readium serve -s s3 --s3-endpoint https://example.com/endpoint --s3-access-key {access-key} --s3-secret-key {secret-key}
| Flag | Description |
|---|---|
--s3-endpoint |
URL for the S3 service |
--s3-access-key |
Access Key for the S3 service |
--s3-secret-key |
Secret Key for the S3 service |
| Flag | Description |
|---|---|
--s3-region |
Region for the S3 service. Defaults to auto. |
In addition to S3, the serve command also supports GCS (Google Cloud Storage).
Unlike S3, support for GCS relies on configuration handled through Application Default Credentials rather than flags when calling the Readium CLI. If running this project in e.g. Google Cloud Run, the credentials will be automatically loaded.
-
Streaming files from GCS.
readium serve -s gs
The serve command is also capable of streaming remote files over HTTP/HTTPS as long as the remote server supports byte range requests.
-
Streaming files over HTTP and HTTPS.
readium serve -s http,https
This feature is currently enabled by default, but will be moved behind a feature flag in future releases.
As illustrated in the previous sections of this document, configuration for the serve commands relies primarily on a -s/--scheme flag that supports a list of comma separated values:
| Scheme | Value |
|---|---|
| Filesystem | file |
| HTTP | http |
| HTTPS | https |
| S3 | s3 |
| Google Cloud Storage | gs |
-
Serving files from both GCS and HTTPS.
readium serve -s gs,https
By default, the serve commands starts an HTTP server on localhost using 15080 as a port.
These settings can be overriden using dedicated flags:
| Flag | Description |
|---|---|
-a or --address |
Address of the HTTP server. |
-p or --port |
Port of the HTTP server. |
In its current version, the serve command relies on a single path from which all manifests can be fetched: /{base64url-encoded-path-to-file}/manifest.json.
Each scheme supports a dedicated URI scheme:
| Scheme | URI scheme | Path |
|---|---|---|
| Filesystem | file:// |
Path to a given file relative to the path provided in --file-directory. |
| HTTP | http:// |
URL |
| HTTPS | https:// |
URL |
| S3 | s3:// |
Path to a bucket, followed by a path to a file (key) in that bucket: s3://{bucket}/{path-to-file} |
| Google Cloud Storage | gs:// |
Path to a bucket, followed by a path to a file (key) in that bucket: gs://{bucket}/{path-to-file} |
Once calculated, the URI scheme and path to the file have to be base64url encoded in order to generate a path to a manifest.
readium serve -s gs,https- I'd like to stream https://github.com/IDPF/epub3-samples/releases/download/20230704/accessible_epub_3.epub
- Which can be base64url encoded to
aHR0cHM6Ly9naXRodWIuY29tL0lEUEYvZXB1YjMtc2FtcGxlcy9yZWxlYXNlcy9kb3dubG9hZC8yMDIzMDcwNC9hY2Nlc3NpYmxlX2VwdWJfMy5lcHVi - The manifest for that file can be accessed at http://localhost:15080/aHR0cHM6Ly9naXRodWIuY29tL0lEUEYvZXB1YjMtc2FtcGxlcy9yZWxlYXNlcy9kb3dubG9hZC8yMDIzMDcwNC9hY2Nlc3NpYmxlX2VwdWJfMy5lcHVi/manifest.json
In addition to the Readium Web Publication Manifest, this commands also provides additional services that can be discovered through the links in each manifest.
In its current version, the CLI provides the following services:
- Position List
- Content Iterator
We expect to deprecate the Content Iterator service in the near future.