@digest/express 3.2.2 → 3.3.3

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 CHANGED
@@ -1,3 +1,2 @@
1
- import type { Router } from 'express';
2
- import type { ServeStaticOptions } from 'serve-static';
3
- export default function (staticPath?: string, baseHref?: any, compression?: boolean, production?: boolean, serveStaticOptions?: ServeStaticOptions): Router;
1
+ declare const app: import("express-serve-static-core").Express;
2
+ export default app;
package/dist/app.js CHANGED
@@ -3,39 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const path_1 = __importDefault(require("path"));
7
- const scripts_1 = __importDefault(require("@digest/scripts"));
8
- const express_1 = require("express");
9
- const express_static_gzip_1 = __importDefault(require("express-static-gzip"));
10
- const serve_static_1 = __importDefault(require("serve-static"));
11
- const router = (0, express_1.Router)();
12
- const defaultServeStaticOptions = {
13
- cacheControl: true,
14
- maxAge: 31536000,
15
- setHeaders: (response, filePath) => {
16
- if (filePath.includes('workbox.js')) {
17
- response.setHeader('Cache-Control', 'max-age=0, no-cache, no-store, must-revalidate');
18
- response.setHeader('Pragma', 'no-cache');
19
- response.setHeader('Expires', '0');
20
- }
21
- }
22
- };
23
- function default_1(staticPath = scripts_1.default.staticPath.replace('/bundle', ''), baseHref = scripts_1.default.baseHref, compression = scripts_1.default.compression, production = scripts_1.default.production, serveStaticOptions) {
24
- const options = Object.assign(Object.assign({}, defaultServeStaticOptions), serveStaticOptions);
25
- if (production &&
26
- compression) {
27
- router.use(baseHref, (0, express_static_gzip_1.default)(staticPath, {
28
- serveStatic: options
29
- }));
30
- }
31
- else {
32
- router.use(baseHref, (0, serve_static_1.default)(staticPath, options));
33
- }
34
- const defaultIndex = path_1.default.join(staticPath, 'index.html');
35
- router.all(`${baseHref}*`, (request, response) => {
36
- response.set('Cache-Control', 'public, max-age=31536000');
37
- response.sendFile(defaultIndex);
38
- });
39
- return router;
40
- }
41
- exports.default = default_1;
6
+ const express_1 = __importDefault(require("express"));
7
+ const helmet_1 = __importDefault(require("helmet"));
8
+ const routers_1 = __importDefault(require("./routers"));
9
+ const server_1 = __importDefault(require("./server"));
10
+ const app = (0, express_1.default)();
11
+ app.use((0, helmet_1.default)(), routers_1.default);
12
+ (0, server_1.default)(app);
13
+ exports.default = app;
@@ -0,0 +1,2 @@
1
+ declare const history: (baseHref: string) => import("express-serve-static-core").Router;
2
+ export default history;
@@ -0,0 +1,30 @@
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 path_1 = __importDefault(require("path"));
7
+ const connect_history_api_fallback_1 = __importDefault(require("connect-history-api-fallback"));
8
+ const express_1 = require("express");
9
+ const ACCEPT_HEADERS = [
10
+ 'text/html',
11
+ 'application/xhtml+xml'
12
+ ];
13
+ const router = (0, express_1.Router)({
14
+ caseSensitive: true,
15
+ strict: true
16
+ });
17
+ const history = (baseHref) => {
18
+ const defaultIndex = 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 = '/*/';
24
+ router.get(historyBase, historyMiddleware);
25
+ router.head(historyBase, historyMiddleware);
26
+ router.get('/', historyMiddleware);
27
+ router.head('/', historyMiddleware);
28
+ return router;
29
+ };
30
+ exports.default = history;
@@ -0,0 +1,2 @@
1
+ declare const routers: import("express-serve-static-core").Router;
2
+ export default routers;
@@ -0,0 +1,19 @@
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 scripts_1 = __importDefault(require("@digest/scripts"));
7
+ const express_1 = require("express");
8
+ const history_1 = __importDefault(require("./history"));
9
+ const statics_1 = __importDefault(require("./statics"));
10
+ const { baseHref, production } = scripts_1.default;
11
+ const staticPath = scripts_1.default.staticPath.replace('/bundle', '');
12
+ const routers = (0, express_1.Router)({
13
+ caseSensitive: true,
14
+ strict: true
15
+ });
16
+ const historyRouter = (0, history_1.default)(baseHref);
17
+ const staticsRouter = (0, statics_1.default)(baseHref, staticPath.replace('/bundle', ''), production);
18
+ routers.use(baseHref, historyRouter, staticsRouter);
19
+ exports.default = routers;
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import expressStatic from 'serve-static';
3
+ declare const statics: (baseHref: string, staticPath: string, production?: boolean, serveStaticOptions?: expressStatic.ServeStaticOptions<import("http").ServerResponse> | undefined) => import("express-serve-static-core").Router;
4
+ export default statics;
@@ -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 router = (0, express_1.Router)({
11
+ caseSensitive: true,
12
+ strict: true
13
+ });
14
+ const defaultServeStaticOptions = {
15
+ immutable: true,
16
+ index: false,
17
+ lastModified: false,
18
+ maxAge: MAX_AGE,
19
+ redirect: false,
20
+ setHeaders: (response, filePath) => {
21
+ if (filePath.includes('workbox.js')) {
22
+ response.setHeader('Cache-Control', 'max-age=0, no-cache, no-store, must-revalidate');
23
+ response.setHeader('Pragma', 'no-cache');
24
+ response.setHeader('Expires', '0');
25
+ }
26
+ }
27
+ };
28
+ const removeBaseHref = (middleware, baseHref) => {
29
+ return (request, response, next) => {
30
+ const fixedRequest = {
31
+ headers: request.headers,
32
+ method: request.method,
33
+ originalUrl: baseHref ?
34
+ request.originalUrl.replace(baseHref, '/') :
35
+ request.originalUrl,
36
+ path: baseHref ?
37
+ request.path.replace(baseHref, '/') :
38
+ request.path,
39
+ url: baseHref ?
40
+ request.url.replace(baseHref, '/') :
41
+ request.url
42
+ };
43
+ return middleware(fixedRequest, response, next);
44
+ };
45
+ };
46
+ const statics = (baseHref, staticPath, production = false, serveStaticOptions) => {
47
+ const options = Object.assign(Object.assign({}, defaultServeStaticOptions), serveStaticOptions);
48
+ const staticBase = '/*';
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;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@digest/express",
3
3
  "title": "Express Digest",
4
4
  "license": "GPL-3.0",
5
- "version": "3.2.2",
5
+ "version": "3.3.3",
6
6
  "description": "Digested Express configurations",
7
7
  "author": "wallzero @wallzeroblog (http://wallzero.com)",
8
8
  "contributors": [
@@ -12,15 +12,19 @@
12
12
  "position": "Initial and Lead Developer"
13
13
  }
14
14
  ],
15
- "main": "dist/start.js",
16
- "types": "dist/start.d.ts",
15
+ "main": "dist/app.js",
16
+ "types": "dist/app.d.ts",
17
17
  "files": [
18
+ "/dist/routers/history.d.ts",
19
+ "/dist/routers/history.js",
20
+ "/dist/routers/index.d.ts",
21
+ "/dist/routers/index.js",
22
+ "/dist/routers/statics.d.ts",
23
+ "/dist/routers/statics.js",
18
24
  "/dist/app.d.ts",
19
25
  "/dist/app.js",
20
26
  "/dist/server.d.ts",
21
27
  "/dist/server.js",
22
- "/dist/start.d.ts",
23
- "/dist/start.js",
24
28
  "/LICENSE.md"
25
29
  ],
26
30
  "homepage": "https://gitlab.com/digested/node-digest/tree/master/packages/express",
@@ -38,11 +42,14 @@
38
42
  "clean": "rimraf node_modules dist package-lock.json npm-debug.log"
39
43
  },
40
44
  "dependencies": {
41
- "@digest/scripts": "^3.2.2",
45
+ "@digest/scripts": "^3.3.3",
46
+ "connect-history-api-fallback": "^1.6.0",
42
47
  "express-static-gzip": "^2.1.1",
48
+ "helmet": "^4.6.0",
43
49
  "serve-static": "^1.14.1"
44
50
  },
45
51
  "devDependencies": {
52
+ "@types/connect-history-api-fallback": "^1.3.5",
46
53
  "@types/express": "^4.17.13",
47
54
  "@types/serve-static": "^1.13.10"
48
55
  },
@@ -53,5 +60,5 @@
53
60
  "digest",
54
61
  "express"
55
62
  ],
56
- "gitHead": "e164547b71e3096174a98b06cdea523ca58c9ad1"
63
+ "gitHead": "c175e05f8214b698d53d7e8edefc003839361319"
57
64
  }
package/dist/start.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const start: import("express-serve-static-core").Express;
2
- export default start;
package/dist/start.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- const express = __importStar(require("express"));
26
- const app_1 = __importDefault(require("./app"));
27
- const server_1 = __importDefault(require("./server"));
28
- const start = express.default();
29
- start.use((0, app_1.default)());
30
- (0, server_1.default)(start);
31
- exports.default = start;