textbrowser 0.44.0 → 0.45.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGES.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # CHANGES to `textbrowser`
2
2
 
3
+ ## 0.45.2
4
+
5
+ - fix: issue with `next`
6
+
7
+ ## 0.45.1
8
+
9
+ - fix: issue with `next`
10
+
11
+ ## 0.45.0
12
+
13
+ - fix: proper use of `await`
14
+ - fix: avoid extra problematic static server call
15
+ - fix: allow for empty router
16
+ - fix: allow fall-through to express if http server fails to match
17
+ - fix: pass on `next` to express
18
+
3
19
  ## 0.44.0
4
20
 
5
21
  - fix: allow passing on if middleware does not match
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "textbrowser",
3
- "version": "0.44.0",
3
+ "version": "0.45.2",
4
4
  "description": "Multilinear text browser",
5
5
  "type": "module",
6
6
  "main": "dist/index-es.min.js",
package/server/main.js CHANGED
@@ -133,27 +133,43 @@ const srv = http.createServer(async (req, res) => {
133
133
  const runHttpServer = async function () {
134
134
  // eslint-disable-next-line no-unsanitized/method -- Site-specified plugin
135
135
  const server = (await import(userParams.httpServer)).default();
136
- server(req, res, next);
136
+ return await server(
137
+ req,
138
+ res,
139
+ // For express, we'll first give a chance to other static servers
140
+ // they might supply
141
+ userParams.expressServer ? () => {
142
+ // Empty
143
+ } : next
144
+ );
137
145
  };
138
146
  if (userParams.expressServer) {
139
147
  // eslint-disable-next-line no-unsanitized/method -- Site-specified plugin
140
148
  const app = (await import(userParams.expressServer)).default();
141
149
 
142
- if (userParams.httpServer && !app._router.stack.some(({regexp}) => {
150
+ if (userParams.httpServer && (!app._router || !app._router.stack.some(({regexp}) => {
143
151
  // Hack to ignore middleware like jsonParser (and hopefully
144
152
  // not get any other)
145
153
  return regexp.source !== '^\\/?(?=\\/|$)' && regexp.test(req.url);
146
- })) {
147
- runHttpServer();
154
+ }))) {
155
+ await runHttpServer();
156
+
157
+ // Ideally we could use `next` here to serve as a back-up static
158
+ // server (i.e., for the bahaiwritings app proper), but the indexes
159
+ // app apparently tries to use it (and fails) after a single
160
+ // successful HTML page load. So we let the Express app handle
161
+ app(req, res, () => {
162
+ // Empty
163
+ });
148
164
  return;
149
165
  }
150
166
 
151
- app.get('*', staticServer);
152
- app(req, res);
167
+ // app.get('*', staticServer);
168
+ app(req, res, next);
153
169
 
154
170
  return;
155
171
  } else if (userParams.httpServer) {
156
- runHttpServer();
172
+ await runHttpServer();
157
173
  return;
158
174
  }
159
175