wapplr 1.0.77 → 1.0.79
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/dist/client/app.js +44 -57
- package/dist/client/createClient.js +47 -57
- package/dist/client/middlewares.js +32 -40
- package/dist/common/contents.js +29 -38
- package/dist/common/middlewares.js +3 -3
- package/dist/common/requests.js +30 -35
- package/dist/common/router.js +33 -45
- package/dist/common/states.js +18 -7
- package/dist/server/app.js +44 -57
- package/dist/server/createServer.js +47 -57
- package/dist/server/middlewares.js +2 -2
- package/dist/server/static.js +91 -45
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports["default"] = createServer;
|
|
8
|
-
var
|
|
8
|
+
var _regenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/regenerator"));
|
|
9
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
10
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
11
11
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
@@ -369,71 +369,64 @@ function createServer() {
|
|
|
369
369
|
"static": app["static"](wapplrServer.config.publicPath)
|
|
370
370
|
}, _rest);
|
|
371
371
|
}
|
|
372
|
-
app.use(
|
|
373
|
-
var _defaultMiddlewaresWrapper = (0, _asyncToGenerator2["default"])(
|
|
374
|
-
var
|
|
375
|
-
return (0,
|
|
376
|
-
while (1) switch (_context3.
|
|
372
|
+
app.use(/*#__PURE__*/function () {
|
|
373
|
+
var _defaultMiddlewaresWrapper = (0, _asyncToGenerator2["default"])(/*#__PURE__*/(0, _regenerator2["default"])().m(function _callee3(req, res, out) {
|
|
374
|
+
var _next, middlewares, index;
|
|
375
|
+
return (0, _regenerator2["default"])().w(function (_context3) {
|
|
376
|
+
while (1) switch (_context3.n) {
|
|
377
377
|
case 0:
|
|
378
378
|
if (wapplrServer.config.disableUseDefaultMiddlewares) {
|
|
379
|
-
_context3.
|
|
379
|
+
_context3.n = 2;
|
|
380
380
|
break;
|
|
381
381
|
}
|
|
382
|
-
|
|
383
|
-
var _ref2 = (0, _asyncToGenerator2["default"])(
|
|
384
|
-
var func, defaultArgs, args;
|
|
385
|
-
return (0,
|
|
386
|
-
while (1) switch (_context2.
|
|
382
|
+
_next = /*#__PURE__*/function () {
|
|
383
|
+
var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/(0, _regenerator2["default"])().m(function _callee2(err) {
|
|
384
|
+
var func, defaultArgs, args, _t;
|
|
385
|
+
return (0, _regenerator2["default"])().w(function (_context2) {
|
|
386
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
387
387
|
case 0:
|
|
388
388
|
if (!middlewares[index]) {
|
|
389
|
-
_context2.
|
|
389
|
+
_context2.n = 5;
|
|
390
390
|
break;
|
|
391
391
|
}
|
|
392
392
|
func = middlewares[index];
|
|
393
393
|
index = index + 1;
|
|
394
|
-
defaultArgs = [req, res, err ? /*#__PURE__*/(0, _asyncToGenerator2["default"])(
|
|
395
|
-
return (0,
|
|
396
|
-
while (1) switch (_context.
|
|
394
|
+
defaultArgs = [req, res, err ? /*#__PURE__*/(0, _asyncToGenerator2["default"])(/*#__PURE__*/(0, _regenerator2["default"])().m(function _callee() {
|
|
395
|
+
return (0, _regenerator2["default"])().w(function (_context) {
|
|
396
|
+
while (1) switch (_context.n) {
|
|
397
397
|
case 0:
|
|
398
|
-
_context.
|
|
399
|
-
return
|
|
400
|
-
case
|
|
401
|
-
|
|
402
|
-
return _context.stop();
|
|
398
|
+
_context.n = 1;
|
|
399
|
+
return _next(err);
|
|
400
|
+
case 1:
|
|
401
|
+
return _context.a(2);
|
|
403
402
|
}
|
|
404
403
|
}, _callee);
|
|
405
|
-
})) :
|
|
404
|
+
})) : _next];
|
|
406
405
|
args = func.length === 4 && err ? [err].concat(defaultArgs) : defaultArgs;
|
|
407
|
-
_context2.
|
|
408
|
-
_context2.
|
|
406
|
+
_context2.p = 1;
|
|
407
|
+
_context2.n = 2;
|
|
409
408
|
return func.apply(void 0, (0, _toConsumableArray2["default"])(args));
|
|
410
|
-
case
|
|
411
|
-
return _context2.
|
|
412
|
-
case
|
|
413
|
-
_context2.
|
|
414
|
-
|
|
415
|
-
res.wappResponse.status(500,
|
|
416
|
-
_context2.
|
|
417
|
-
return
|
|
418
|
-
case
|
|
419
|
-
return _context2.
|
|
420
|
-
case
|
|
421
|
-
_context2.next = 22;
|
|
422
|
-
break;
|
|
423
|
-
case 19:
|
|
409
|
+
case 2:
|
|
410
|
+
return _context2.a(2, _context2.v);
|
|
411
|
+
case 3:
|
|
412
|
+
_context2.p = 3;
|
|
413
|
+
_t = _context2.v;
|
|
414
|
+
res.wappResponse.status(500, _t);
|
|
415
|
+
_context2.n = 4;
|
|
416
|
+
return _next(_t);
|
|
417
|
+
case 4:
|
|
418
|
+
return _context2.a(2, _context2.v);
|
|
419
|
+
case 5:
|
|
424
420
|
if (!(typeof out === "function")) {
|
|
425
|
-
_context2.
|
|
421
|
+
_context2.n = 6;
|
|
426
422
|
break;
|
|
427
423
|
}
|
|
428
424
|
index = 0;
|
|
429
|
-
return _context2.
|
|
430
|
-
case
|
|
431
|
-
return _context2.
|
|
432
|
-
case 23:
|
|
433
|
-
case "end":
|
|
434
|
-
return _context2.stop();
|
|
425
|
+
return _context2.a(2, out(err));
|
|
426
|
+
case 6:
|
|
427
|
+
return _context2.a(2, null);
|
|
435
428
|
}
|
|
436
|
-
}, _callee2, null, [[
|
|
429
|
+
}, _callee2, null, [[1, 3]]);
|
|
437
430
|
}));
|
|
438
431
|
return function next(_x4) {
|
|
439
432
|
return _ref2.apply(this, arguments);
|
|
@@ -443,18 +436,15 @@ function createServer() {
|
|
|
443
436
|
return wapplrServer.middlewares[key];
|
|
444
437
|
});
|
|
445
438
|
index = 0;
|
|
446
|
-
_context3.
|
|
447
|
-
return
|
|
448
|
-
case
|
|
449
|
-
return _context3.
|
|
450
|
-
case
|
|
451
|
-
_context3.
|
|
439
|
+
_context3.n = 1;
|
|
440
|
+
return _next();
|
|
441
|
+
case 1:
|
|
442
|
+
return _context3.a(2, _context3.v);
|
|
443
|
+
case 2:
|
|
444
|
+
_context3.n = 3;
|
|
452
445
|
return out();
|
|
453
|
-
case
|
|
454
|
-
return _context3.
|
|
455
|
-
case 10:
|
|
456
|
-
case "end":
|
|
457
|
-
return _context3.stop();
|
|
446
|
+
case 3:
|
|
447
|
+
return _context3.a(2, _context3.v);
|
|
458
448
|
}
|
|
459
449
|
}, _callee3);
|
|
460
450
|
}));
|
|
@@ -275,8 +275,8 @@ function createMiddlewares(p) {
|
|
|
275
275
|
var mtime = stats.mtime,
|
|
276
276
|
size = stats.size;
|
|
277
277
|
if (!res.getHeader("ETag") && mtime && size) {
|
|
278
|
-
var
|
|
279
|
-
res.setHeader("ETag",
|
|
278
|
+
var _etag = "W/\"".concat(size.toString(16), "-").concat(mtime.getTime().toString(16), "\"");
|
|
279
|
+
res.setHeader("ETag", _etag);
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
282
|
return next();
|
package/dist/server/static.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.addCloseEventsForReadableStream = addCloseEventsForReadableStream;
|
|
7
8
|
exports["default"] = serveStatic;
|
|
8
9
|
exports.endStream = endStream;
|
|
9
|
-
var
|
|
10
|
+
var _regenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/regenerator"));
|
|
11
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
+
var fs = require("node:fs/promises");
|
|
13
|
+
var fsSync = require("node:fs");
|
|
10
14
|
var path = require("path");
|
|
11
15
|
function destroy(stream) {
|
|
12
16
|
if (!(stream !== null && stream !== void 0 && stream.__destroyed)) {
|
|
@@ -81,49 +85,91 @@ function addCloseEventsForReadableStream(req, res, stream) {
|
|
|
81
85
|
});
|
|
82
86
|
}
|
|
83
87
|
function serveStatic(publicPath) {
|
|
84
|
-
return function
|
|
85
|
-
var
|
|
86
|
-
pathname
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
88
|
+
return /*#__PURE__*/function () {
|
|
89
|
+
var _staticMiddleware = (0, _asyncToGenerator2["default"])(/*#__PURE__*/(0, _regenerator2["default"])().m(function _callee(req, res, next) {
|
|
90
|
+
var parsedUrl, sanitizePath, pathname, parsedSanitizePath, ext, stream, data, stats, _t, _t2;
|
|
91
|
+
return (0, _regenerator2["default"])().w(function (_context) {
|
|
92
|
+
while (1) switch (_context.p = _context.n) {
|
|
93
|
+
case 0:
|
|
94
|
+
parsedUrl = {
|
|
95
|
+
pathname: req.wappRequest.path
|
|
96
|
+
};
|
|
97
|
+
try {
|
|
98
|
+
parsedUrl = new URL(req.wappRequest.url);
|
|
99
|
+
} catch (e) {}
|
|
100
|
+
sanitizePath = path.normalize(parsedUrl.pathname).replace(/^(\.\.[\/\\])+/, "");
|
|
101
|
+
pathname = path.join(publicPath, sanitizePath);
|
|
102
|
+
parsedSanitizePath = path.parse(pathname);
|
|
103
|
+
ext = parsedSanitizePath.ext;
|
|
104
|
+
if (ext) {
|
|
105
|
+
_context.n = 2;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
_context.n = 1;
|
|
109
|
+
return next();
|
|
110
|
+
case 1:
|
|
111
|
+
return _context.a(2, _context.v);
|
|
112
|
+
case 2:
|
|
113
|
+
_context.p = 2;
|
|
114
|
+
_context.n = 3;
|
|
115
|
+
return fs.access(pathname);
|
|
116
|
+
case 3:
|
|
117
|
+
_context.n = 6;
|
|
118
|
+
break;
|
|
119
|
+
case 4:
|
|
120
|
+
_context.p = 4;
|
|
121
|
+
_t = _context.v;
|
|
122
|
+
_context.n = 5;
|
|
123
|
+
return next();
|
|
124
|
+
case 5:
|
|
125
|
+
return _context.a(2, _context.v);
|
|
126
|
+
case 6:
|
|
127
|
+
_context.p = 6;
|
|
128
|
+
_context.n = 7;
|
|
129
|
+
return fs.readFile(pathname);
|
|
130
|
+
case 7:
|
|
131
|
+
data = _context.v;
|
|
132
|
+
_context.n = 8;
|
|
133
|
+
return fs.stat(pathname);
|
|
134
|
+
case 8:
|
|
135
|
+
stats = _context.v;
|
|
136
|
+
res.wappResponse.status(200);
|
|
137
|
+
res.wappResponse.sendData = {
|
|
138
|
+
data: data,
|
|
139
|
+
stats: stats,
|
|
140
|
+
parsedPath: parsedSanitizePath
|
|
141
|
+
};
|
|
142
|
+
stream = fsSync.createReadStream(pathname);
|
|
143
|
+
addCloseEventsForReadableStream(req, res, stream);
|
|
144
|
+
stream.on("error", function onerror(err) {
|
|
145
|
+
endStream(req, res, stream);
|
|
146
|
+
res.wappResponse.status(err.statusCode || 500, err);
|
|
147
|
+
res.wapp.log(err, req, res);
|
|
148
|
+
next(err);
|
|
149
|
+
});
|
|
150
|
+
stream.on("open", function onopen() {
|
|
151
|
+
res.wapp.middleware.runSendMiddlewares(req, res, function next() {
|
|
152
|
+
res.wapp.log(req, res);
|
|
153
|
+
stream.pipe(res);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
_context.n = 10;
|
|
157
|
+
break;
|
|
158
|
+
case 9:
|
|
159
|
+
_context.p = 9;
|
|
160
|
+
_t2 = _context.v;
|
|
161
|
+
endStream(req, res, stream);
|
|
162
|
+
res.wappResponse.status(_t2.statusCode || 500, _t2);
|
|
163
|
+
res.wapp.log(_t2, req, res);
|
|
164
|
+
next(_t2);
|
|
165
|
+
case 10:
|
|
166
|
+
return _context.a(2);
|
|
167
|
+
}
|
|
168
|
+
}, _callee, null, [[6, 9], [2, 4]]);
|
|
169
|
+
}));
|
|
170
|
+
function staticMiddleware(_x, _x2, _x3) {
|
|
171
|
+
return _staticMiddleware.apply(this, arguments);
|
|
127
172
|
}
|
|
128
|
-
|
|
173
|
+
return staticMiddleware;
|
|
174
|
+
}();
|
|
129
175
|
}
|