@digest/express 4.14.5 → 4.14.8-next.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/dist/app.d.ts +3 -0
- package/dist/app.js +73 -0
- package/dist/routers/history.d.ts +3 -0
- package/dist/routers/history.js +29 -0
- package/dist/routers/index.d.ts +3 -0
- package/dist/routers/index.js +21 -0
- package/dist/routers/statics.d.ts +4 -0
- package/dist/routers/statics.js +60 -0
- package/dist/routers/stats.d.ts +3 -0
- package/dist/routers/stats.js +25 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +10 -0
- package/package.json +2 -2
package/dist/app.d.ts
ADDED
package/dist/app.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const routers_1 = __importDefault(require("./routers"));
|
|
40
|
+
const server_1 = __importDefault(require("./server"));
|
|
41
|
+
const scripts_1 = require("@digest/scripts");
|
|
42
|
+
const connect_slashes_1 = __importDefault(require("connect-slashes"));
|
|
43
|
+
const express_1 = __importDefault(require("express"));
|
|
44
|
+
const helmet_1 = __importStar(require("helmet"));
|
|
45
|
+
const app = (0, express_1.default)();
|
|
46
|
+
app.use((0, helmet_1.default)(), routers_1.default, (0, connect_slashes_1.default)(false));
|
|
47
|
+
if (scripts_1.production) {
|
|
48
|
+
app.use((0, helmet_1.contentSecurityPolicy)({
|
|
49
|
+
directives: {
|
|
50
|
+
scriptSrc: [
|
|
51
|
+
'\'self\'',
|
|
52
|
+
'\'wasm-unsafe-eval\''
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
app.use((0, helmet_1.contentSecurityPolicy)({
|
|
59
|
+
directives: {
|
|
60
|
+
defaultSrc: [
|
|
61
|
+
'\'self\'',
|
|
62
|
+
'\'unsafe-inline\''
|
|
63
|
+
],
|
|
64
|
+
scriptSrc: [
|
|
65
|
+
'\'self\'',
|
|
66
|
+
'\'wasm-unsafe-eval\''
|
|
67
|
+
],
|
|
68
|
+
upgradeInsecureRequests: null
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
(0, server_1.default)(app);
|
|
73
|
+
exports.default = app;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const connect_history_api_fallback_1 = __importDefault(require("connect-history-api-fallback"));
|
|
7
|
+
const express_1 = require("express");
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const ACCEPT_HEADERS = [
|
|
10
|
+
'text/html',
|
|
11
|
+
'application/xhtml+xml'
|
|
12
|
+
];
|
|
13
|
+
const history = (baseHref = '/') => {
|
|
14
|
+
const router = (0, express_1.Router)({
|
|
15
|
+
caseSensitive: true,
|
|
16
|
+
strict: true
|
|
17
|
+
});
|
|
18
|
+
const defaultIndex = node_path_1.default.join(baseHref, 'index.html');
|
|
19
|
+
const historyMiddleware = (0, connect_history_api_fallback_1.default)({
|
|
20
|
+
htmlAcceptHeaders: ACCEPT_HEADERS,
|
|
21
|
+
index: defaultIndex
|
|
22
|
+
});
|
|
23
|
+
const historyBase = '/{*expressHistoryPath}';
|
|
24
|
+
router.get(historyBase, historyMiddleware);
|
|
25
|
+
router.head(historyBase, historyMiddleware);
|
|
26
|
+
router.options(historyBase, historyMiddleware);
|
|
27
|
+
return router;
|
|
28
|
+
};
|
|
29
|
+
exports.default = history;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const history_1 = __importDefault(require("./history"));
|
|
7
|
+
const statics_1 = __importDefault(require("./statics"));
|
|
8
|
+
const stats_1 = __importDefault(require("./stats"));
|
|
9
|
+
const scripts_1 = require("@digest/scripts");
|
|
10
|
+
const express_1 = require("express");
|
|
11
|
+
const { baseHref } = scripts_1.config;
|
|
12
|
+
const staticPath = scripts_1.config.staticPath;
|
|
13
|
+
const routers = (0, express_1.Router)({
|
|
14
|
+
caseSensitive: true,
|
|
15
|
+
strict: true
|
|
16
|
+
});
|
|
17
|
+
const statsRouter = (0, stats_1.default)();
|
|
18
|
+
const historyRouter = (0, history_1.default)(baseHref);
|
|
19
|
+
const staticsRouter = (0, statics_1.default)(baseHref, staticPath, scripts_1.production);
|
|
20
|
+
routers.use(baseHref, statsRouter, historyRouter, staticsRouter);
|
|
21
|
+
exports.default = routers;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const express_1 = require("express");
|
|
7
|
+
const express_static_gzip_1 = __importDefault(require("express-static-gzip"));
|
|
8
|
+
const serve_static_1 = __importDefault(require("serve-static"));
|
|
9
|
+
const MAX_AGE = 31536000;
|
|
10
|
+
const defaultServeStaticOptions = {
|
|
11
|
+
immutable: true,
|
|
12
|
+
index: false,
|
|
13
|
+
lastModified: false,
|
|
14
|
+
maxAge: MAX_AGE,
|
|
15
|
+
redirect: false,
|
|
16
|
+
setHeaders: (response, filePath) => {
|
|
17
|
+
if (filePath.includes('workbox.js')) {
|
|
18
|
+
response.setHeader('Cache-Control', 'max-age=0, no-cache, no-store, must-revalidate');
|
|
19
|
+
response.setHeader('Pragma', 'no-cache');
|
|
20
|
+
response.setHeader('Expires', '0');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const removeBaseHref = (middleware, baseHref) => {
|
|
25
|
+
return (request, response, next) => {
|
|
26
|
+
const fixedRequest = {
|
|
27
|
+
headers: request.headers,
|
|
28
|
+
method: request.method,
|
|
29
|
+
originalUrl: baseHref ?
|
|
30
|
+
request.originalUrl.replace(baseHref, '/') :
|
|
31
|
+
request.originalUrl,
|
|
32
|
+
path: baseHref ?
|
|
33
|
+
request.path.replace(baseHref, '/') :
|
|
34
|
+
request.path,
|
|
35
|
+
url: baseHref ?
|
|
36
|
+
request.url.replace(baseHref, '/') :
|
|
37
|
+
request.url
|
|
38
|
+
};
|
|
39
|
+
return middleware(fixedRequest, response, next);
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const statics = (baseHref, staticPath, production = false, serveStaticOptions) => {
|
|
43
|
+
const router = (0, express_1.Router)({
|
|
44
|
+
caseSensitive: true,
|
|
45
|
+
strict: true
|
|
46
|
+
});
|
|
47
|
+
const options = Object.assign(Object.assign({}, defaultServeStaticOptions), serveStaticOptions);
|
|
48
|
+
const staticBase = '/{*expressStaticPath}';
|
|
49
|
+
const serveStatic = removeBaseHref(production ?
|
|
50
|
+
(0, express_static_gzip_1.default)(staticPath, {
|
|
51
|
+
enableBrotli: true,
|
|
52
|
+
index: false,
|
|
53
|
+
serveStatic: options
|
|
54
|
+
}) :
|
|
55
|
+
(0, serve_static_1.default)(staticPath, options), baseHref);
|
|
56
|
+
router.get(staticBase, serveStatic);
|
|
57
|
+
router.head(staticBase, serveStatic);
|
|
58
|
+
return router;
|
|
59
|
+
};
|
|
60
|
+
exports.default = statics;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const express_1 = require("express");
|
|
4
|
+
const helmet_1 = require("helmet");
|
|
5
|
+
const stats = () => {
|
|
6
|
+
const router = (0, express_1.Router)({
|
|
7
|
+
caseSensitive: true,
|
|
8
|
+
strict: true
|
|
9
|
+
});
|
|
10
|
+
const helmetMiddleware = (0, helmet_1.contentSecurityPolicy)({
|
|
11
|
+
directives: {
|
|
12
|
+
'script-src': [
|
|
13
|
+
'\'self\'',
|
|
14
|
+
'\'unsafe-inline\''
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
useDefaults: true
|
|
18
|
+
});
|
|
19
|
+
const statsPath = '/stats/*';
|
|
20
|
+
router.get(statsPath, helmetMiddleware);
|
|
21
|
+
router.head(statsPath, helmetMiddleware);
|
|
22
|
+
router.options(statsPath, helmetMiddleware);
|
|
23
|
+
return router;
|
|
24
|
+
};
|
|
25
|
+
exports.default = stats;
|
package/dist/server.d.ts
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const scripts_1 = require("@digest/scripts");
|
|
5
|
+
function default_1(app) {
|
|
6
|
+
return app.listen(scripts_1.config.appPort, scripts_1.config.appHost, () => {
|
|
7
|
+
console.info(`Listening on http://${scripts_1.config.appHost}:${scripts_1.config.appPort}${scripts_1.config.baseHref}`);
|
|
8
|
+
return app;
|
|
9
|
+
});
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@digest/express",
|
|
3
3
|
"title": "Express Digest",
|
|
4
4
|
"license": "LGPL-3.0-or-later",
|
|
5
|
-
"version": "4.14.
|
|
5
|
+
"version": "4.14.8-next.1",
|
|
6
6
|
"description": "Digested Express configurations",
|
|
7
7
|
"author": "wallzero @wallzeroblog (http://wallzero.com)",
|
|
8
8
|
"contributors": [
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"digest",
|
|
64
64
|
"express"
|
|
65
65
|
],
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "2f4145c4391be317be01156076e642eeae4d4453"
|
|
67
67
|
}
|