-
Notifications
You must be signed in to change notification settings - Fork 34
/
server.ts
87 lines (77 loc) · 2.76 KB
/
server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// ES5 import (assuming node_modules/r2-streamer-js/):
import { Server } from "dita-streamer-js";
import * as express from "express";
import * as path from "path";
import recursive from "recursive-readdir";
async function start() {
// Constructor parameter is optional:
// disableDecryption: true
// disableOPDS
// disableReaders: true
// disableRemotePubUrl: true to deactivate
const server = new Server({
disableDecryption: true, // deactivates the decryption of encrypted resources (Readium LCP).
disableOPDS: true, // deactivates the HTTP routes for the OPDS "micro services" (browser, converter)
disableReaders: false, // deactivates the built-in "readers" for ReadiumWebPubManifest (HTTP static host / route).
disableRemotePubUrl: true, // deactivates the HTTP route for loading a remote publication.
maxPrefetchLinks: 5, // Link HTTP header, with rel = prefetch, see server.ts MAX_PREFETCH_LINKS (default = 10)
readers: [
{
title: "Dita Example",
getUrl: (url) => `/viewer/index_dita.html?url=${url}`,
},
{
title: "Dita Sample Read",
getUrl: (url) => `/viewer/index_sampleread.html?url=${url}`,
},
{
title: "Minimal Example",
getUrl: (url) => `/viewer/index_minimal.html?url=${url}`,
},
{
title: "API Example",
getUrl: (url) => `/viewer/index_api.html?url=${url}`,
},
{
title: "Static Placeholder PDF Example",
getUrl: (url) => `/viewer/index_pdf.html?url=${url}`,
},
],
});
/**
* Serve our viewer examples, and allow unresolved requests to fall through
* to the following static handler from /dist
*/
server.expressUse(
"/viewer",
//@ts-ignore
express.static(path.join(__dirname, "../viewer"), { fallthrough: true })
);
/**
* Serve our built application bundles from /dist
*/
// @ts-ignore
server.expressUse("/viewer", express.static(path.join(__dirname, "../dist")));
/**
* Serve our sample EPUBS from /examples/epubs
*/
const epubsPath = path.join(__dirname, "./epubs");
recursive(epubsPath, ["!*.epub"], function (err, files) {
if (err) return console.error(err);
const filePaths = files.map((fileName) => path.join(fileName));
const publicationURLs = server.addPublications(filePaths);
console.log("Local Publications: ", publicationURLs.length);
});
const data = await server.start(4444, false);
// http://127.0.0.1:3000
// Note that ports 80 and 443 (HTTPS) are always implicit (ommitted).
console.log(
`Dev server (R2 Streamer) running at url: http://localhost:${data.urlPort}}`
);
// // Calls `uncachePublications()` (see below)
// server.stop();
// console.log(server.isStarted()); // false
}
(async () => {
await start();
})();