wapplr 1.0.74 → 1.0.76
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 +183 -243
- package/dist/client/config.js +1 -5
- package/dist/client/createClient.js +88 -134
- package/dist/client/history.js +10 -39
- package/dist/client/index.js +0 -15
- package/dist/client/middlewares.js +93 -168
- package/dist/common/config.js +1 -4
- package/dist/common/contents.js +91 -142
- package/dist/common/index.js +7 -18
- package/dist/common/log/index.js +27 -48
- package/dist/common/log/renderedContent.js +57 -70
- package/dist/common/logo/index.js +0 -2
- package/dist/common/middlewares.js +7 -61
- package/dist/common/requests.js +97 -143
- package/dist/common/router.js +97 -162
- package/dist/common/states.js +7 -68
- package/dist/common/styles.js +6 -51
- package/dist/common/template/index.js +19 -24
- package/dist/common/template/template_css.js +1 -1
- package/dist/common/utils.js +4 -18
- package/dist/server/app.js +151 -217
- package/dist/server/config.js +1 -13
- package/dist/server/createServer.js +110 -197
- package/dist/server/html.js +35 -46
- package/dist/server/index.js +1 -16
- package/dist/server/middlewares.js +14 -73
- package/dist/server/static.js +0 -26
- package/package.json +1 -1
package/dist/common/router.js
CHANGED
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.createDefaultRouter = createDefaultRouter;
|
|
9
8
|
exports["default"] = createRouter;
|
|
10
|
-
|
|
11
9
|
var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
|
|
12
|
-
|
|
13
10
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
14
|
-
|
|
15
11
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
16
|
-
|
|
17
12
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
18
|
-
|
|
19
13
|
var _utils = require("./utils");
|
|
20
|
-
|
|
21
14
|
var _excluded = ["action"],
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
_excluded2 = ["wapp"];
|
|
24
16
|
function createDefaultRouter() {
|
|
25
17
|
var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
26
18
|
var wapp = p.wapp,
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
routes = p.routes;
|
|
29
20
|
function match() {
|
|
30
21
|
var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
31
22
|
var path = p.path;
|
|
@@ -36,7 +27,6 @@ function createDefaultRouter() {
|
|
|
36
27
|
if (path && r.path) {
|
|
37
28
|
var _match = false;
|
|
38
29
|
var thisParams = {};
|
|
39
|
-
|
|
40
30
|
try {
|
|
41
31
|
var rPath = r.path.slice(-1) === "/" ? r.path.slice(0, -1) : r.path;
|
|
42
32
|
var sPath = path.slice(-1) === "/" ? path.slice(0, -1) : path;
|
|
@@ -47,31 +37,25 @@ function createDefaultRouter() {
|
|
|
47
37
|
rpa.forEach(function (rpas, i) {
|
|
48
38
|
var param = rpas && rpas.slice(0, 1) === ":";
|
|
49
39
|
var allow = rpas === "*";
|
|
50
|
-
|
|
51
40
|
if (allow) {
|
|
52
41
|
wasAllowChar = true;
|
|
53
42
|
}
|
|
54
|
-
|
|
55
43
|
if (typeof pa[i] == "string") {
|
|
56
44
|
if (pa[i] === rpas || param || allow) {} else {
|
|
57
45
|
allPartIsMatch = false;
|
|
58
46
|
}
|
|
59
|
-
|
|
60
47
|
if (param) {
|
|
61
48
|
thisParams[rpas.slice(1)] = pa[i];
|
|
62
49
|
}
|
|
63
50
|
}
|
|
64
51
|
});
|
|
65
|
-
|
|
66
52
|
if (pa.length > rpa.length && !wasAllowChar) {
|
|
67
53
|
allPartIsMatch = false;
|
|
68
54
|
}
|
|
69
|
-
|
|
70
55
|
if (allPartIsMatch) {
|
|
71
56
|
_match = true;
|
|
72
57
|
}
|
|
73
58
|
} catch (e) {}
|
|
74
|
-
|
|
75
59
|
if (_match && !route) {
|
|
76
60
|
params = thisParams;
|
|
77
61
|
route = r;
|
|
@@ -82,7 +66,6 @@ function createDefaultRouter() {
|
|
|
82
66
|
params: params
|
|
83
67
|
}) : route;
|
|
84
68
|
}
|
|
85
|
-
|
|
86
69
|
function getRoute() {
|
|
87
70
|
var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
88
71
|
var path = p.path;
|
|
@@ -90,12 +73,10 @@ function createDefaultRouter() {
|
|
|
90
73
|
requestPath: null,
|
|
91
74
|
status: null
|
|
92
75
|
};
|
|
93
|
-
|
|
94
76
|
if (path) {
|
|
95
77
|
var routeByPath = router.match({
|
|
96
78
|
path: path
|
|
97
79
|
});
|
|
98
|
-
|
|
99
80
|
if (routeByPath) {
|
|
100
81
|
r = (0, _objectSpread2["default"])({
|
|
101
82
|
requestPath: path,
|
|
@@ -103,7 +84,6 @@ function createDefaultRouter() {
|
|
|
103
84
|
}, routeByPath);
|
|
104
85
|
}
|
|
105
86
|
}
|
|
106
|
-
|
|
107
87
|
if (!r.status) {
|
|
108
88
|
var notFoundPath = router.match({
|
|
109
89
|
path: "/404"
|
|
@@ -118,7 +98,6 @@ function createDefaultRouter() {
|
|
|
118
98
|
path: router.routes[0].path
|
|
119
99
|
}) : null;
|
|
120
100
|
var foundPath = notFoundPath ? notFoundPath : homePath ? homePath : firstPath ? firstPath : (0, _objectSpread2["default"])({}, r);
|
|
121
|
-
|
|
122
101
|
if (foundPath) {
|
|
123
102
|
r = (0, _objectSpread2["default"])({
|
|
124
103
|
requestPath: path,
|
|
@@ -126,94 +105,79 @@ function createDefaultRouter() {
|
|
|
126
105
|
}, foundPath);
|
|
127
106
|
}
|
|
128
107
|
}
|
|
129
|
-
|
|
130
108
|
return r;
|
|
131
109
|
}
|
|
132
|
-
|
|
133
110
|
function defaultResolve() {
|
|
134
111
|
return _defaultResolve.apply(this, arguments);
|
|
135
112
|
}
|
|
136
|
-
|
|
137
113
|
function _defaultResolve() {
|
|
138
114
|
_defaultResolve = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
|
|
139
115
|
var p,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
116
|
+
path,
|
|
117
|
+
req,
|
|
118
|
+
res,
|
|
119
|
+
_router$getRoute,
|
|
120
|
+
_router$getRoute$acti,
|
|
121
|
+
action,
|
|
122
|
+
rest,
|
|
123
|
+
r,
|
|
124
|
+
_args = arguments;
|
|
150
125
|
return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
|
|
151
|
-
while (1) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
case 10:
|
|
180
|
-
case "end":
|
|
181
|
-
return _context.stop();
|
|
182
|
-
}
|
|
126
|
+
while (1) switch (_context.prev = _context.next) {
|
|
127
|
+
case 0:
|
|
128
|
+
p = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
129
|
+
path = p.path, req = p.req, res = p.res;
|
|
130
|
+
_router$getRoute = router.getRoute({
|
|
131
|
+
path: path
|
|
132
|
+
}), _router$getRoute$acti = _router$getRoute.action, action = _router$getRoute$acti === void 0 ? defaultAction : _router$getRoute$acti, rest = (0, _objectWithoutProperties2["default"])(_router$getRoute, _excluded);
|
|
133
|
+
_context.next = 5;
|
|
134
|
+
return action((0, _objectSpread2["default"])({
|
|
135
|
+
wapp: wapp,
|
|
136
|
+
req: req,
|
|
137
|
+
res: res
|
|
138
|
+
}, rest));
|
|
139
|
+
case 5:
|
|
140
|
+
r = _context.sent;
|
|
141
|
+
_context.next = 8;
|
|
142
|
+
return router.action((0, _objectSpread2["default"])({
|
|
143
|
+
wapp: wapp,
|
|
144
|
+
req: req,
|
|
145
|
+
res: res
|
|
146
|
+
}, r));
|
|
147
|
+
case 8:
|
|
148
|
+
r = _context.sent;
|
|
149
|
+
return _context.abrupt("return", r);
|
|
150
|
+
case 10:
|
|
151
|
+
case "end":
|
|
152
|
+
return _context.stop();
|
|
183
153
|
}
|
|
184
154
|
}, _callee);
|
|
185
155
|
}));
|
|
186
156
|
return _defaultResolve.apply(this, arguments);
|
|
187
157
|
}
|
|
188
|
-
|
|
189
158
|
function defaultAction() {
|
|
190
159
|
return _defaultAction.apply(this, arguments);
|
|
191
160
|
}
|
|
192
|
-
|
|
193
161
|
function _defaultAction() {
|
|
194
162
|
_defaultAction = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee2() {
|
|
195
163
|
var p,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
164
|
+
wapp,
|
|
165
|
+
rest,
|
|
166
|
+
_args2 = arguments;
|
|
199
167
|
return (0, _regeneratorRuntime2["default"])().wrap(function _callee2$(_context2) {
|
|
200
|
-
while (1) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
case "end":
|
|
209
|
-
return _context2.stop();
|
|
210
|
-
}
|
|
168
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
169
|
+
case 0:
|
|
170
|
+
p = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
171
|
+
wapp = p.wapp, rest = (0, _objectWithoutProperties2["default"])(p, _excluded2);
|
|
172
|
+
return _context2.abrupt("return", (0, _objectSpread2["default"])({}, rest));
|
|
173
|
+
case 3:
|
|
174
|
+
case "end":
|
|
175
|
+
return _context2.stop();
|
|
211
176
|
}
|
|
212
177
|
}, _callee2);
|
|
213
178
|
}));
|
|
214
179
|
return _defaultAction.apply(this, arguments);
|
|
215
180
|
}
|
|
216
|
-
|
|
217
181
|
function defaultAdd(obj) {
|
|
218
182
|
if (typeof obj === "object" && obj.length) {
|
|
219
183
|
obj.forEach(function (route) {
|
|
@@ -224,7 +188,6 @@ function createDefaultRouter() {
|
|
|
224
188
|
foundRoute = true;
|
|
225
189
|
}
|
|
226
190
|
});
|
|
227
|
-
|
|
228
191
|
if (!foundRoute) {
|
|
229
192
|
router.routes.push(route);
|
|
230
193
|
}
|
|
@@ -238,14 +201,12 @@ function createDefaultRouter() {
|
|
|
238
201
|
foundRoute = true;
|
|
239
202
|
}
|
|
240
203
|
});
|
|
241
|
-
|
|
242
204
|
if (!foundRoute) {
|
|
243
205
|
router.routes.push(obj);
|
|
244
206
|
}
|
|
245
207
|
}
|
|
246
208
|
}
|
|
247
209
|
}
|
|
248
|
-
|
|
249
210
|
function defaultReplace(obj) {
|
|
250
211
|
if (typeof obj === "object" && obj.length) {
|
|
251
212
|
obj.forEach(function (objRoute) {
|
|
@@ -257,7 +218,6 @@ function createDefaultRouter() {
|
|
|
257
218
|
replaced = true;
|
|
258
219
|
}
|
|
259
220
|
});
|
|
260
|
-
|
|
261
221
|
if (!replaced) {
|
|
262
222
|
router.routes.push(objRoute);
|
|
263
223
|
}
|
|
@@ -272,14 +232,12 @@ function createDefaultRouter() {
|
|
|
272
232
|
replaced = true;
|
|
273
233
|
}
|
|
274
234
|
});
|
|
275
|
-
|
|
276
235
|
if (!replaced) {
|
|
277
236
|
router.routes.push(obj);
|
|
278
237
|
}
|
|
279
238
|
}
|
|
280
239
|
}
|
|
281
240
|
}
|
|
282
|
-
|
|
283
241
|
var defaultRoutes = routes || [{
|
|
284
242
|
path: "/",
|
|
285
243
|
contentName: "log"
|
|
@@ -315,74 +273,60 @@ function createDefaultRouter() {
|
|
|
315
273
|
});
|
|
316
274
|
return router;
|
|
317
275
|
}
|
|
318
|
-
|
|
319
276
|
function createRouter() {
|
|
320
277
|
var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
321
278
|
var wapp = p.wapp,
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
279
|
+
_p$routeManager = p.routeManager,
|
|
280
|
+
routeManager = _p$routeManager === void 0 ? createDefaultRouter(p) : _p$routeManager;
|
|
325
281
|
function defaultHandle(_x, _x2, _x3) {
|
|
326
282
|
return _defaultHandle.apply(this, arguments);
|
|
327
283
|
}
|
|
328
|
-
|
|
329
284
|
function _defaultHandle() {
|
|
330
285
|
_defaultHandle = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee3(req, res, next) {
|
|
331
286
|
var wappResponse, wappRequest, routerRes, path, route;
|
|
332
287
|
return (0, _regeneratorRuntime2["default"])().wrap(function _callee3$(_context3) {
|
|
333
|
-
while (1) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
wappResponse.
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
case 13:
|
|
366
|
-
return _context3.abrupt("return", next());
|
|
367
|
-
|
|
368
|
-
case 14:
|
|
369
|
-
case "end":
|
|
370
|
-
return _context3.stop();
|
|
371
|
-
}
|
|
288
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
289
|
+
case 0:
|
|
290
|
+
wappResponse = res.wappResponse;
|
|
291
|
+
wappRequest = req.wappRequest;
|
|
292
|
+
routerRes = routerMiddleware.routeManager.resolve;
|
|
293
|
+
path = wappRequest.path || wappRequest.url;
|
|
294
|
+
_context3.next = 6;
|
|
295
|
+
return routerRes({
|
|
296
|
+
path: path,
|
|
297
|
+
req: req,
|
|
298
|
+
res: res
|
|
299
|
+
});
|
|
300
|
+
case 6:
|
|
301
|
+
route = _context3.sent;
|
|
302
|
+
wappResponse.statusCode = wappResponse.statusCode === 200 || !wappResponse.statusCode ? route.status : wappResponse.statusCode;
|
|
303
|
+
wappResponse.route = route;
|
|
304
|
+
if (wappResponse.statusCode) {
|
|
305
|
+
wappResponse.status(wappResponse.statusCode);
|
|
306
|
+
}
|
|
307
|
+
if (!(wappRequest.path === "/500" && wappResponse.statusCode === 404)) {
|
|
308
|
+
_context3.next = 13;
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
//test an error
|
|
312
|
+
wappResponse.route.contentName = "";
|
|
313
|
+
throw new Error("Internal Server Error (Test)");
|
|
314
|
+
case 13:
|
|
315
|
+
return _context3.abrupt("return", next());
|
|
316
|
+
case 14:
|
|
317
|
+
case "end":
|
|
318
|
+
return _context3.stop();
|
|
372
319
|
}
|
|
373
320
|
}, _callee3);
|
|
374
321
|
}));
|
|
375
322
|
return _defaultHandle.apply(this, arguments);
|
|
376
323
|
}
|
|
377
|
-
|
|
378
324
|
function defaultAdd(p) {
|
|
379
325
|
return routerMiddleware.routeManager.add(p);
|
|
380
326
|
}
|
|
381
|
-
|
|
382
327
|
function defaultReplace(p) {
|
|
383
328
|
return routerMiddleware.routeManager.replace(p);
|
|
384
329
|
}
|
|
385
|
-
|
|
386
330
|
var routerMiddlewareProperties = Object.create(Object.prototype, {
|
|
387
331
|
handle: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _utils.defaultDescriptor), {}, {
|
|
388
332
|
value: defaultHandle
|
|
@@ -397,41 +341,32 @@ function createRouter() {
|
|
|
397
341
|
value: defaultReplace
|
|
398
342
|
})
|
|
399
343
|
});
|
|
400
|
-
|
|
401
344
|
function routerMiddleware(_x4, _x5, _x6) {
|
|
402
345
|
return _routerMiddleware.apply(this, arguments);
|
|
403
346
|
}
|
|
404
|
-
|
|
405
347
|
function _routerMiddleware() {
|
|
406
348
|
_routerMiddleware = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee4(req, res, next) {
|
|
407
349
|
return (0, _regeneratorRuntime2["default"])().wrap(function _callee4$(_context4) {
|
|
408
|
-
while (1) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
return _context4.abrupt("return", routerMiddleware);
|
|
424
|
-
|
|
425
|
-
case 5:
|
|
426
|
-
case "end":
|
|
427
|
-
return _context4.stop();
|
|
428
|
-
}
|
|
350
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
351
|
+
case 0:
|
|
352
|
+
if (!(typeof routerMiddleware.handle === "function")) {
|
|
353
|
+
_context4.next = 4;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
_context4.next = 3;
|
|
357
|
+
return routerMiddleware.handle(req, res, next);
|
|
358
|
+
case 3:
|
|
359
|
+
return _context4.abrupt("return", _context4.sent);
|
|
360
|
+
case 4:
|
|
361
|
+
return _context4.abrupt("return", routerMiddleware);
|
|
362
|
+
case 5:
|
|
363
|
+
case "end":
|
|
364
|
+
return _context4.stop();
|
|
429
365
|
}
|
|
430
366
|
}, _callee4);
|
|
431
367
|
}));
|
|
432
368
|
return _routerMiddleware.apply(this, arguments);
|
|
433
369
|
}
|
|
434
|
-
|
|
435
370
|
(0, _utils.mergeProperties)(routerMiddleware, routerMiddlewareProperties);
|
|
436
371
|
Object.defineProperty(routerMiddleware, "wapp", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _utils.defaultDescriptor), {}, {
|
|
437
372
|
writable: false,
|