@digest/koa 3.3.1 → 3.3.2
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 -5
- package/dist/app.js +7 -39
- package/dist/middleware/history.d.ts +4 -0
- package/dist/middleware/history.js +32 -0
- package/dist/routers/history.d.ts +5 -0
- package/dist/routers/history.js +28 -0
- package/dist/routers/index.d.ts +5 -0
- package/dist/routers/index.js +19 -0
- package/dist/routers/statics.d.ts +6 -0
- package/dist/routers/statics.js +32 -0
- package/package.json +16 -8
- package/dist/start.d.ts +0 -3
- package/dist/start.js +0 -13
package/dist/app.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { Options } from 'koa-static';
|
|
5
|
-
export default function (staticPath?: string, baseHref?: any, production?: boolean, serveStaticOptions?: Options): Router<import("koa").DefaultState, import("koa").DefaultContext>;
|
|
1
|
+
import Koa from 'koa';
|
|
2
|
+
declare const app: Koa<Koa.DefaultState, Koa.DefaultContext>;
|
|
3
|
+
export default app;
|
package/dist/app.js
CHANGED
|
@@ -1,45 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const
|
|
16
|
-
const router_1 = __importDefault(require("@koa/router"));
|
|
6
|
+
const koa_1 = __importDefault(require("koa"));
|
|
17
7
|
const koa_helmet_1 = __importDefault(require("koa-helmet"));
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
maxAge: MAX_AGE,
|
|
25
|
-
setHeaders: (response, filePath) => {
|
|
26
|
-
if (filePath.includes('workbox.js')) {
|
|
27
|
-
response.setHeader('Cache-Control', 'max-age=0, no-cache, no-store, must-revalidate');
|
|
28
|
-
response.setHeader('Pragma', 'no-cache');
|
|
29
|
-
response.setHeader('Expires', '0');
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
function default_1(staticPath = scripts_1.default.staticPath.replace('/bundle', ''), baseHref = scripts_1.default.baseHref, production = scripts_1.default.production, serveStaticOptions) {
|
|
34
|
-
const options = Object.assign(Object.assign({ brotli: Boolean(production), gzip: Boolean(production) }, defaultServeStaticOptions), serveStaticOptions);
|
|
35
|
-
router.use((0, koa_helmet_1.default)());
|
|
36
|
-
router.use(baseHref, (0, koa_mount_1.default)(baseHref, (0, koa_static_1.default)(staticPath, options)));
|
|
37
|
-
router.all(`${baseHref}(.*)`, (context) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
yield (0, koa_send_1.default)(context, 'index.html', {
|
|
39
|
-
maxAge: MAX_AGE,
|
|
40
|
-
root: staticPath
|
|
41
|
-
});
|
|
42
|
-
}));
|
|
43
|
-
return router;
|
|
44
|
-
}
|
|
45
|
-
exports.default = default_1;
|
|
8
|
+
const routers_1 = __importDefault(require("./routers"));
|
|
9
|
+
const server_1 = __importDefault(require("./server"));
|
|
10
|
+
const app = new koa_1.default();
|
|
11
|
+
app.use((0, koa_helmet_1.default)()).use(routers_1.default.routes()).use(routers_1.default.allowedMethods());
|
|
12
|
+
(0, server_1.default)(app);
|
|
13
|
+
exports.default = app;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const koa_history_api_fallback_1 = __importDefault(require("koa-history-api-fallback"));
|
|
16
|
+
const history = (options) => {
|
|
17
|
+
const middleware = (0, koa_history_api_fallback_1.default)(options);
|
|
18
|
+
const historyMiddleware = (context, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
if (context.state.history) {
|
|
20
|
+
yield next();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const nextRoute = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
context.state.history = true;
|
|
25
|
+
yield context.router.routes()(context, next);
|
|
26
|
+
});
|
|
27
|
+
yield middleware(context, nextRoute);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return historyMiddleware;
|
|
31
|
+
};
|
|
32
|
+
exports.default = history;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 router_1 = __importDefault(require("@koa/router"));
|
|
8
|
+
const history_1 = __importDefault(require("../middleware/history"));
|
|
9
|
+
const ACCEPT_HEADERS = [
|
|
10
|
+
'text/html',
|
|
11
|
+
'application/xhtml+xml'
|
|
12
|
+
];
|
|
13
|
+
const router = new router_1.default({
|
|
14
|
+
sensitive: true,
|
|
15
|
+
strict: true
|
|
16
|
+
});
|
|
17
|
+
const history = (baseHref) => {
|
|
18
|
+
const defaultIndex = path_1.default.join(baseHref, 'index.html');
|
|
19
|
+
const historyMiddleware = (0, history_1.default)({
|
|
20
|
+
htmlAcceptHeaders: ACCEPT_HEADERS,
|
|
21
|
+
index: defaultIndex
|
|
22
|
+
});
|
|
23
|
+
const historyBase = '(.*)/';
|
|
24
|
+
router.get(historyBase, historyMiddleware);
|
|
25
|
+
router.head(historyBase, historyMiddleware);
|
|
26
|
+
return router;
|
|
27
|
+
};
|
|
28
|
+
exports.default = history;
|
|
@@ -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 router_1 = __importDefault(require("@koa/router"));
|
|
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 = new router_1.default({
|
|
13
|
+
sensitive: 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, staticsRouter.routes(), staticsRouter.allowedMethods(), historyRouter.routes(), historyRouter.allowedMethods());
|
|
19
|
+
exports.default = routers;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="koa" />
|
|
2
|
+
/// <reference types="koa__router" />
|
|
3
|
+
import Router from '@koa/router';
|
|
4
|
+
import type { Options } from 'koa-static';
|
|
5
|
+
declare const statics: (baseHref: string, staticPath: string, production?: boolean, serveStaticOptions?: Options | undefined) => Router<import("koa").DefaultState, import("koa").DefaultContext>;
|
|
6
|
+
export default statics;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 router_1 = __importDefault(require("@koa/router"));
|
|
7
|
+
const koa_mount_1 = __importDefault(require("koa-mount"));
|
|
8
|
+
const koa_static_1 = __importDefault(require("koa-static"));
|
|
9
|
+
const MAX_AGE = 31536000;
|
|
10
|
+
const router = new router_1.default({
|
|
11
|
+
sensitive: true,
|
|
12
|
+
strict: true
|
|
13
|
+
});
|
|
14
|
+
const defaultServeStaticOptions = {
|
|
15
|
+
maxAge: MAX_AGE,
|
|
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 statics = (baseHref, staticPath, production = false, serveStaticOptions) => {
|
|
25
|
+
const options = Object.assign(Object.assign({ brotli: production, defer: true, gzip: production }, defaultServeStaticOptions), serveStaticOptions);
|
|
26
|
+
const staticBase = '(.*)';
|
|
27
|
+
const serveStatic = (0, koa_static_1.default)(staticPath, options);
|
|
28
|
+
router.get(staticBase, (0, koa_mount_1.default)(baseHref, serveStatic));
|
|
29
|
+
router.head(staticBase, (0, koa_mount_1.default)(baseHref, serveStatic));
|
|
30
|
+
return router;
|
|
31
|
+
};
|
|
32
|
+
exports.default = statics;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@digest/koa",
|
|
3
3
|
"title": "Koa Digest",
|
|
4
4
|
"license": "GPL-3.0",
|
|
5
|
-
"version": "3.3.
|
|
5
|
+
"version": "3.3.2",
|
|
6
6
|
"description": "Digested Koa configurations",
|
|
7
7
|
"author": "wallzero @wallzeroblog (http://wallzero.com)",
|
|
8
8
|
"contributors": [
|
|
@@ -12,15 +12,21 @@
|
|
|
12
12
|
"position": "Initial and Lead Developer"
|
|
13
13
|
}
|
|
14
14
|
],
|
|
15
|
-
"main": "dist/
|
|
16
|
-
"types": "dist/
|
|
15
|
+
"main": "dist/app.js",
|
|
16
|
+
"types": "dist/app.d.ts",
|
|
17
17
|
"files": [
|
|
18
|
+
"/dist/middleware/history.d.ts",
|
|
19
|
+
"/dist/middleware/history.js",
|
|
20
|
+
"/dist/routers/history.d.ts",
|
|
21
|
+
"/dist/routers/history.js",
|
|
22
|
+
"/dist/routers/index.d.ts",
|
|
23
|
+
"/dist/routers/index.js",
|
|
24
|
+
"/dist/routers/statics.d.ts",
|
|
25
|
+
"/dist/routers/statics.js",
|
|
18
26
|
"/dist/app.d.ts",
|
|
19
27
|
"/dist/app.js",
|
|
20
28
|
"/dist/server.d.ts",
|
|
21
29
|
"/dist/server.js",
|
|
22
|
-
"/dist/start.d.ts",
|
|
23
|
-
"/dist/start.js",
|
|
24
30
|
"/LICENSE.md"
|
|
25
31
|
],
|
|
26
32
|
"homepage": "https://gitlab.com/digested/node-digest/tree/master/packages/koa",
|
|
@@ -38,21 +44,23 @@
|
|
|
38
44
|
"clean": "rimraf node_modules dist package-lock.json npm-debug.log"
|
|
39
45
|
},
|
|
40
46
|
"dependencies": {
|
|
41
|
-
"@digest/scripts": "^3.3.
|
|
47
|
+
"@digest/scripts": "^3.3.2",
|
|
42
48
|
"@koa/router": "^10.1.1",
|
|
43
49
|
"koa": "^2.13.4",
|
|
44
50
|
"koa-helmet": "^6.1.0",
|
|
51
|
+
"koa-history-api-fallback": "^1.0.0",
|
|
45
52
|
"koa-mount": "^4.0.0",
|
|
46
53
|
"koa-send": "^5.0.1",
|
|
47
54
|
"koa-static": "^5.0.0"
|
|
48
55
|
},
|
|
49
56
|
"devDependencies": {
|
|
57
|
+
"@types/connect-history-api-fallback": "^1.3.5",
|
|
50
58
|
"@types/koa": "^2.13.4",
|
|
51
59
|
"@types/koa-helmet": "^6.0.4",
|
|
52
60
|
"@types/koa-mount": "^4.0.1",
|
|
53
61
|
"@types/koa-send": "^4.1.3",
|
|
54
62
|
"@types/koa-static": "^4.0.2",
|
|
55
|
-
"@types/koa__router": "^8.0.
|
|
63
|
+
"@types/koa__router": "^8.0.11"
|
|
56
64
|
},
|
|
57
65
|
"peerDependencies": {
|
|
58
66
|
"koa": "^2.13.4"
|
|
@@ -61,5 +69,5 @@
|
|
|
61
69
|
"digest",
|
|
62
70
|
"koa"
|
|
63
71
|
],
|
|
64
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "97df5e3e791d3bcac2eddc0d26b37b828b49e1e7"
|
|
65
73
|
}
|
package/dist/start.d.ts
DELETED
package/dist/start.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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 koa_1 = __importDefault(require("koa"));
|
|
7
|
-
const app_1 = __importDefault(require("./app"));
|
|
8
|
-
const server_1 = __importDefault(require("./server"));
|
|
9
|
-
const start = new koa_1.default();
|
|
10
|
-
const router = (0, app_1.default)();
|
|
11
|
-
start.use(router.routes()).use(router.allowedMethods());
|
|
12
|
-
(0, server_1.default)(start);
|
|
13
|
-
exports.default = start;
|