textbrowser 0.43.0 → 0.45.1
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 +17 -1
- package/package.json +1 -1
- package/server/main.js +34 -8
package/CHANGES.md
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
# textbrowser
|
|
1
|
+
# CHANGES to `textbrowser`
|
|
2
|
+
|
|
3
|
+
## 0.45.1
|
|
4
|
+
|
|
5
|
+
- fix: issue with `next`
|
|
6
|
+
|
|
7
|
+
## 0.45.0
|
|
8
|
+
|
|
9
|
+
- fix: proper use of `await`
|
|
10
|
+
- fix: avoid extra problematic static server call
|
|
11
|
+
- fix: allow for empty router
|
|
12
|
+
- fix: allow fall-through to express if http server fails to match
|
|
13
|
+
- fix: pass on `next` to express
|
|
14
|
+
|
|
15
|
+
## 0.44.0
|
|
16
|
+
|
|
17
|
+
- fix: allow passing on if middleware does not match
|
|
2
18
|
|
|
3
19
|
## 0.43.0
|
|
4
20
|
|
package/package.json
CHANGED
package/server/main.js
CHANGED
|
@@ -122,27 +122,53 @@ const srv = http.createServer(async (req, res) => {
|
|
|
122
122
|
}
|
|
123
123
|
fileServer.serve(req, res);
|
|
124
124
|
};
|
|
125
|
+
|
|
126
|
+
const next = function () {
|
|
127
|
+
req.addListener('end', staticServer).resume();
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @returns {Promise<void>}
|
|
132
|
+
*/
|
|
133
|
+
const runHttpServer = async function () {
|
|
134
|
+
// eslint-disable-next-line no-unsanitized/method -- Site-specified plugin
|
|
135
|
+
const server = (await import(userParams.httpServer)).default();
|
|
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
|
+
);
|
|
145
|
+
};
|
|
125
146
|
if (userParams.expressServer) {
|
|
126
147
|
// eslint-disable-next-line no-unsanitized/method -- Site-specified plugin
|
|
127
148
|
const app = (await import(userParams.expressServer)).default();
|
|
128
149
|
|
|
129
|
-
if (userParams.httpServer && !app._router.stack.some(({regexp}) => {
|
|
150
|
+
if (userParams.httpServer && (!app._router || !app._router.stack.some(({regexp}) => {
|
|
130
151
|
// Hack to ignore middleware like jsonParser (and hopefully
|
|
131
152
|
// not get any other)
|
|
132
153
|
return regexp.source !== '^\\/?(?=\\/|$)' && regexp.test(req.url);
|
|
133
|
-
})) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
154
|
+
}))) {
|
|
155
|
+
await runHttpServer();
|
|
156
|
+
app(req, res, () => {
|
|
157
|
+
// Empty
|
|
158
|
+
});
|
|
137
159
|
return;
|
|
138
160
|
}
|
|
139
161
|
|
|
140
|
-
app.get('*', staticServer);
|
|
141
|
-
app(req, res);
|
|
162
|
+
// app.get('*', staticServer);
|
|
163
|
+
app(req, res, next);
|
|
142
164
|
|
|
165
|
+
return;
|
|
166
|
+
} else if (userParams.httpServer) {
|
|
167
|
+
await runHttpServer();
|
|
143
168
|
return;
|
|
144
169
|
}
|
|
145
|
-
|
|
170
|
+
|
|
171
|
+
next();
|
|
146
172
|
/*
|
|
147
173
|
res.writeHead(404, {'Content-Type': 'text/html'});
|
|
148
174
|
res.end('<h1>File not found</h1>');
|