alp-node 3.2.2 → 4.0.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/.eslintrc.json +1 -1
- package/AlpNodeApp.js +1 -8
- package/CHANGELOG.md +49 -0
- package/dist/{AlpNodeApp-node12-dev.mjs → AlpNodeApp-node14.mjs} +2 -2
- package/dist/AlpNodeApp-node14.mjs.map +1 -0
- package/dist/AlpNodeApp.d.ts +2 -2
- package/dist/AlpNodeApp.d.ts.map +1 -1
- package/dist/fetch-node14.mjs +5 -0
- package/dist/fetch-node14.mjs.map +1 -0
- package/dist/fetch.d.ts +6 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/{index-node12.mjs → index-node14.mjs} +5 -8
- package/dist/index-node14.mjs.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/fetch.js +2 -3
- package/package.json +41 -47
- package/rollup.config.mjs +3 -0
- package/src/.eslintrc.json +19 -2
- package/src/AlpNodeApp.ts +7 -4
- package/src/fetch.ts +11 -0
- package/src/index.ts +7 -6
- package/dist/AlpNodeApp-node12-dev.cjs.js +0 -121
- package/dist/AlpNodeApp-node12-dev.cjs.js.map +0 -1
- package/dist/AlpNodeApp-node12-dev.mjs.map +0 -1
- package/dist/AlpNodeApp-node12.cjs.js +0 -121
- package/dist/AlpNodeApp-node12.cjs.js.map +0 -1
- package/dist/AlpNodeApp-node12.mjs +0 -103
- package/dist/AlpNodeApp-node12.mjs.map +0 -1
- package/dist/index-node12-dev.cjs.js +0 -162
- package/dist/index-node12-dev.cjs.js.map +0 -1
- package/dist/index-node12-dev.mjs +0 -140
- package/dist/index-node12-dev.mjs.map +0 -1
- package/dist/index-node12.cjs.js +0 -162
- package/dist/index-node12.cjs.js.map +0 -1
- package/dist/index-node12.mjs.map +0 -1
- package/fetch.mjs +0 -3
- package/index.js +0 -6
package/.eslintrc.json
CHANGED
package/AlpNodeApp.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const production = process.env.NODE_ENV === 'production';
|
|
6
|
-
module.exports = require(`./dist/AlpNodeApp-node12${
|
|
7
|
-
production ? '' : '-dev'
|
|
8
|
-
}.cjs`);
|
|
1
|
+
export * from './dist/AlpNodeApp-node14.mjs';
|
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,55 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.0.3](https://github.com/christophehurpeau/alp/compare/alp-node@4.0.2...alp-node@4.0.3) (2022-01-15)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package alp-node
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [4.0.2](https://github.com/christophehurpeau/alp/compare/alp-node@4.0.1...alp-node@4.0.2) (2022-01-02)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* extra entries ([fbfb15f](https://github.com/christophehurpeau/alp/commit/fbfb15fd4cfc474ccb803105fb8ece71414a6f5d))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [4.0.1](https://github.com/christophehurpeau/alp/compare/alp-node@4.0.0...alp-node@4.0.1) (2022-01-02)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package alp-node
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# [4.0.0](https://github.com/christophehurpeau/alp/compare/alp-node@3.2.2...alp-node@4.0.0) (2022-01-02)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Bug Fixes
|
|
37
|
+
|
|
38
|
+
* remove findup-sync ([0f7ac09](https://github.com/christophehurpeau/alp/commit/0f7ac09d577de99eff3a559f54c0d9891c0aa265))
|
|
39
|
+
* update nightingale and fix tests ([3691716](https://github.com/christophehurpeau/alp/commit/36917162d0ee3dccc07384caf018b7760d98b744))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Features
|
|
43
|
+
|
|
44
|
+
* use ESM and drop node 12 ([f45054e](https://github.com/christophehurpeau/alp/commit/f45054e931eea88451d183722797eba057511236))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### BREAKING CHANGES
|
|
48
|
+
|
|
49
|
+
* requires node 14 and ESM
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
6
55
|
## [3.2.2](https://github.com/christophehurpeau/alp/compare/alp-node@3.2.1...alp-node@3.2.2) (2021-04-10)
|
|
7
56
|
|
|
8
57
|
**Note:** Version bump only for package alp-node
|
|
@@ -9,7 +9,7 @@ import translate from 'alp-translate';
|
|
|
9
9
|
import Koa from 'koa';
|
|
10
10
|
import compress from 'koa-compress';
|
|
11
11
|
import serve from 'koa-static';
|
|
12
|
-
import Logger from 'nightingale-logger';
|
|
12
|
+
import { Logger } from 'nightingale-logger';
|
|
13
13
|
|
|
14
14
|
const logger = new Logger('alp');
|
|
15
15
|
class AlpNodeApp extends Koa {
|
|
@@ -100,4 +100,4 @@ class AlpNodeApp extends Koa {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
export { AlpNodeApp };
|
|
103
|
-
//# sourceMappingURL=AlpNodeApp-
|
|
103
|
+
//# sourceMappingURL=AlpNodeApp-node14.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlpNodeApp-node14.mjs","sources":["../src/AlpNodeApp.ts"],"sourcesContent":["import type { IncomingMessage, Server, ServerResponse } from 'http';\nimport path from 'path';\nimport { deprecate } from 'util';\nimport _listen from 'alp-listen';\nimport type { Config } from 'alp-node-config';\nimport _config from 'alp-node-config';\nimport errors from 'alp-node-errors';\nimport language from 'alp-node-language';\nimport params from 'alp-params';\nimport translate from 'alp-translate';\nimport type {\n NodeApplication,\n NodeConfig,\n Context as AlpContext,\n ContextState,\n ContextSanitizedState,\n} from 'alp-types';\nimport Koa from 'koa';\nimport type { ParameterizedContext, DefaultState } from 'koa';\nimport compress from 'koa-compress';\nimport serve from 'koa-static';\nimport { Logger } from 'nightingale-logger';\n\nconst logger = new Logger('alp');\n\nexport interface AlpNodeAppOptions {\n appDirname: string;\n packageDirname: string;\n config: Config & NodeConfig;\n certPath?: string;\n publicPath?: string;\n}\n\ndeclare module 'koa' {\n // eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-shadow\n interface DefaultState extends ContextState {}\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n interface DefaultContext extends AlpContext {}\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n interface BaseContext extends AlpContext {}\n}\n\nexport class AlpNodeApp extends Koa<ContextState> implements NodeApplication {\n dirname: string;\n\n certPath: string;\n\n publicPath: string;\n\n config: NodeConfig & Config;\n\n _server?: Server;\n\n /**\n * @param {Object} [options]\n * @param {string} [options.certPath] directory of the ssl certificates\n * @param {string} [options.publicPath] directory of public files\n */\n constructor({\n appDirname,\n packageDirname,\n config,\n certPath,\n publicPath,\n }: AlpNodeAppOptions) {\n super();\n\n this.dirname = path.normalize(appDirname);\n\n Object.defineProperty(this, 'packageDirname', {\n get: deprecate(() => packageDirname, 'packageDirname'),\n configurable: false,\n enumerable: false,\n });\n\n this.certPath = certPath || `${packageDirname}/config/cert`;\n this.publicPath = publicPath || `${packageDirname}/public/`;\n\n this.config = _config(this, config);\n this.context.config = this.config;\n\n params(this);\n language(this);\n translate('locales')(this);\n\n this.use(compress());\n }\n\n existsConfigSync(name: string): ReturnType<Config['existsConfigSync']> {\n return this.config.existsConfigSync(name);\n }\n\n loadConfigSync(name: string): ReturnType<Config['loadConfigSync']> {\n return this.config.loadConfigSync(name);\n }\n\n createContext<StateT = DefaultState>(\n req: IncomingMessage,\n res: ServerResponse,\n ): ParameterizedContext<StateT> {\n const ctx = super.createContext<StateT>(req, res);\n ctx.sanitizedState = {} as ContextSanitizedState;\n return ctx;\n }\n\n servePublic(): void {\n this.use(serve(this.publicPath)); // static files\n }\n\n catchErrors(): void {\n this.use(errors);\n }\n\n listen(): Server {\n throw new Error('Use start instead');\n }\n\n /**\n * Close server and emit close event\n */\n close(): void {\n if (this._server) {\n this._server.close();\n this.emit('close');\n }\n }\n\n async start(fn: () => Promise<void> | void): Promise<Server> {\n await fn();\n try {\n const server = await _listen(this.config, this.callback(), this.certPath);\n this._server = server;\n logger.success('started');\n if (process.send) process.send('ready');\n return server;\n } catch (err: unknown) {\n logger.error('start fail', { err });\n throw err;\n }\n }\n}\n\nexport type { Context } from 'koa';\n"],"names":["logger","Logger","AlpNodeApp","Koa","constructor","appDirname","packageDirname","config","certPath","publicPath","dirname","path","normalize","Object","defineProperty","get","deprecate","configurable","enumerable","_config","context","params","language","translate","use","compress","existsConfigSync","name","loadConfigSync","createContext","req","res","ctx","sanitizedState","servePublic","serve","catchErrors","errors","listen","Error","close","_server","emit","start","fn","server","_listen","callback","success","process","send","err","error"],"mappings":";;;;;;;;;;;;;AAuBA,MAAMA,MAAM,GAAG,IAAIC,MAAJ,CAAW,KAAX,CAAf;AAmBO,MAAMC,UAAN,SAAyBC,GAAzB,CAAsE;AAW3E;AACF;AACA;AACA;AACA;AACEC,EAAAA,WAAW,CAAC;AACVC,IAAAA,UADU;AAEVC,IAAAA,cAFU;AAGVC,IAAAA,MAHU;AAIVC,IAAAA,QAJU;AAKVC,IAAAA;AALU,GAAD,EAMW;AACpB;AAEA,SAAKC,OAAL,GAAeC,IAAI,CAACC,SAAL,CAAeP,UAAf,CAAf;AAEAQ,IAAAA,MAAM,CAACC,cAAP,CAAsB,IAAtB,EAA4B,gBAA5B,EAA8C;AAC5CC,MAAAA,GAAG,EAAEC,SAAS,CAAC,MAAMV,cAAP,EAAuB,gBAAvB,CAD8B;AAE5C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AAL,CAAaD,KAAb;;AACA,WAAKE,IAAL,CAAU,OAAV;AACD;AACF;;AAEU,QAALC,KAAK,CAACC,EAAD,EAAkD;AAC3D,UAAMA,EAAE,EAAR;;AACA,QAAI;AACF,YAAMC,MAAM,GAAG,MAAMC,OAAO,CAAC,KAAKvC,MAAN,EAAc,KAAKwC,QAAL,EAAd,EAA+B,KAAKvC,QAApC,CAA5B;AACA,WAAKiC,OAAL,GAAeI,MAAf;AACA7C,MAAAA,MAAM,CAACgD,OAAP,CAAe,SAAf;AACA,UAAIC,OAAO,CAACC,IAAZ,EAAkBD,OAAO,CAACC,IAAR,CAAa,OAAb;AAClB,aAAOL,MAAP;AACD,KAND,CAME,OAAOM,GAAP,EAAqB;AACrBnD,MAAAA,MAAM,CAACoD,KAAP,CAAa,YAAb,EAA2B;AAAED,QAAAA;AAAF,OAA3B;AACA,YAAMA,GAAN;AACD;AACF;;AAjG0E;;;;"}
|
package/dist/AlpNodeApp.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { IncomingMessage, Server, ServerResponse } from 'http';
|
|
|
3
3
|
import type { Config } from 'alp-node-config';
|
|
4
4
|
import type { NodeApplication, NodeConfig, Context as AlpContext, ContextState } from 'alp-types';
|
|
5
5
|
import Koa from 'koa';
|
|
6
|
-
import type { ParameterizedContext, DefaultState
|
|
6
|
+
import type { ParameterizedContext, DefaultState } from 'koa';
|
|
7
7
|
export interface AlpNodeAppOptions {
|
|
8
8
|
appDirname: string;
|
|
9
9
|
packageDirname: string;
|
|
@@ -19,7 +19,6 @@ declare module 'koa' {
|
|
|
19
19
|
interface BaseContext extends AlpContext {
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
export type { Context };
|
|
23
22
|
export declare class AlpNodeApp extends Koa<ContextState> implements NodeApplication {
|
|
24
23
|
dirname: string;
|
|
25
24
|
certPath: string;
|
|
@@ -44,4 +43,5 @@ export declare class AlpNodeApp extends Koa<ContextState> implements NodeApplica
|
|
|
44
43
|
close(): void;
|
|
45
44
|
start(fn: () => Promise<void> | void): Promise<Server>;
|
|
46
45
|
}
|
|
46
|
+
export type { Context } from 'koa';
|
|
47
47
|
//# sourceMappingURL=AlpNodeApp.d.ts.map
|
package/dist/AlpNodeApp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlpNodeApp.d.ts","sourceRoot":"","sources":["../src/AlpNodeApp.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAIpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAM9C,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,OAAO,IAAI,UAAU,EACrB,YAAY,EAEb,MAAM,WAAW,CAAC;AACnB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"AlpNodeApp.d.ts","sourceRoot":"","sources":["../src/AlpNodeApp.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAIpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAM9C,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,OAAO,IAAI,UAAU,EACrB,YAAY,EAEb,MAAM,WAAW,CAAC;AACnB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,KAAK,CAAC;AAO9D,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,OAAO,QAAQ,KAAK,CAAC;IAEnB,UAAU,YAAa,SAAQ,YAAY;KAAG;IAE9C,UAAU,cAAe,SAAQ,UAAU;KAAG;IAE9C,UAAU,WAAY,SAAQ,UAAU;KAAG;CAC5C;AAED,qBAAa,UAAW,SAAQ,GAAG,CAAC,YAAY,CAAE,YAAW,eAAe;IAC1E,OAAO,EAAE,MAAM,CAAC;IAEhB,QAAQ,EAAE,MAAM,CAAC;IAEjB,UAAU,EAAE,MAAM,CAAC;IAEnB,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC;IAE5B,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;gBACS,EACV,UAAU,EACV,cAAc,EACd,MAAM,EACN,QAAQ,EACR,UAAU,GACX,EAAE,iBAAiB;IAwBpB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAItE,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAIlE,aAAa,CAAC,MAAM,GAAG,YAAY,EACjC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,GAClB,oBAAoB,CAAC,MAAM,CAAC;IAM/B,WAAW,IAAI,IAAI;IAInB,WAAW,IAAI,IAAI;IAInB,MAAM,IAAI,MAAM;IAIhB;;OAEG;IACH,KAAK,IAAI,IAAI;IAOP,KAAK,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;CAa7D;AAED,YAAY,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-node14.mjs","sources":["../src/fetch.ts"],"sourcesContent":["import nodeFetch from 'node-fetch';\n\ndeclare global {\n // eslint-disable-next-line vars-on-top, no-var\n var fetch: typeof nodeFetch;\n}\n\nglobal.fetch = nodeFetch;\n\n// eslint-disable-next-line unicorn/prefer-export-from\nexport default nodeFetch;\n"],"names":["global","fetch","nodeFetch"],"mappings":";;;AAOAA,MAAM,CAACC,KAAP,GAAeC,SAAf"}
|
package/dist/fetch.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,KAAK,EAAE,OAAO,SAAS,CAAC;CAC7B;AAKD,eAAe,SAAS,CAAC"}
|
|
@@ -2,8 +2,7 @@ import { readFileSync, existsSync } from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import _config, { Config } from 'alp-node-config';
|
|
4
4
|
export { Config } from 'alp-node-config';
|
|
5
|
-
import
|
|
6
|
-
import Logger from 'nightingale-logger';
|
|
5
|
+
import { Logger } from 'nightingale-logger';
|
|
7
6
|
import { deprecate } from 'util';
|
|
8
7
|
import _listen from 'alp-listen';
|
|
9
8
|
import errors from 'alp-node-errors';
|
|
@@ -13,6 +12,7 @@ import translate from 'alp-translate';
|
|
|
13
12
|
import Koa from 'koa';
|
|
14
13
|
import compress from 'koa-compress';
|
|
15
14
|
import serve from 'koa-static';
|
|
15
|
+
export { default as fetch } from 'node-fetch';
|
|
16
16
|
|
|
17
17
|
const logger$1 = new Logger('alp');
|
|
18
18
|
class AlpNodeApp extends Koa {
|
|
@@ -105,9 +105,7 @@ class AlpNodeApp extends Koa {
|
|
|
105
105
|
const logger = new Logger('alp'); // see alp-dev
|
|
106
106
|
|
|
107
107
|
const appDirname = path.resolve('build');
|
|
108
|
-
const packagePath =
|
|
109
|
-
cwd: appDirname
|
|
110
|
-
});
|
|
108
|
+
const packagePath = path.resolve('package.json');
|
|
111
109
|
|
|
112
110
|
if (!packagePath) {
|
|
113
111
|
throw new Error(`Could not find package.json: "${String(packagePath)}"`);
|
|
@@ -135,6 +133,5 @@ class App extends AlpNodeApp {
|
|
|
135
133
|
|
|
136
134
|
}
|
|
137
135
|
|
|
138
|
-
export default
|
|
139
|
-
|
|
140
|
-
//# sourceMappingURL=index-node12.mjs.map
|
|
136
|
+
export { appDirname, config, App as default, packageConfig, packageDirname };
|
|
137
|
+
//# sourceMappingURL=index-node14.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-node14.mjs","sources":["../src/AlpNodeApp.ts","../src/index.ts"],"sourcesContent":["import type { IncomingMessage, Server, ServerResponse } from 'http';\nimport path from 'path';\nimport { deprecate } from 'util';\nimport _listen from 'alp-listen';\nimport type { Config } from 'alp-node-config';\nimport _config from 'alp-node-config';\nimport errors from 'alp-node-errors';\nimport language from 'alp-node-language';\nimport params from 'alp-params';\nimport translate from 'alp-translate';\nimport type {\n NodeApplication,\n NodeConfig,\n Context as AlpContext,\n ContextState,\n ContextSanitizedState,\n} from 'alp-types';\nimport Koa from 'koa';\nimport type { ParameterizedContext, DefaultState } from 'koa';\nimport compress from 'koa-compress';\nimport serve from 'koa-static';\nimport { Logger } from 'nightingale-logger';\n\nconst logger = new Logger('alp');\n\nexport interface AlpNodeAppOptions {\n appDirname: string;\n packageDirname: string;\n config: Config & NodeConfig;\n certPath?: string;\n publicPath?: string;\n}\n\ndeclare module 'koa' {\n // eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-shadow\n interface DefaultState extends ContextState {}\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n interface DefaultContext extends AlpContext {}\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n interface BaseContext extends AlpContext {}\n}\n\nexport class AlpNodeApp extends Koa<ContextState> implements NodeApplication {\n dirname: string;\n\n certPath: string;\n\n publicPath: string;\n\n config: NodeConfig & Config;\n\n _server?: Server;\n\n /**\n * @param {Object} [options]\n * @param {string} [options.certPath] directory of the ssl certificates\n * @param {string} [options.publicPath] directory of public files\n */\n constructor({\n appDirname,\n packageDirname,\n config,\n certPath,\n publicPath,\n }: AlpNodeAppOptions) {\n super();\n\n this.dirname = path.normalize(appDirname);\n\n Object.defineProperty(this, 'packageDirname', {\n get: deprecate(() => packageDirname, 'packageDirname'),\n configurable: false,\n enumerable: false,\n });\n\n this.certPath = certPath || `${packageDirname}/config/cert`;\n this.publicPath = publicPath || `${packageDirname}/public/`;\n\n this.config = _config(this, config);\n this.context.config = this.config;\n\n params(this);\n language(this);\n translate('locales')(this);\n\n this.use(compress());\n }\n\n existsConfigSync(name: string): ReturnType<Config['existsConfigSync']> {\n return this.config.existsConfigSync(name);\n }\n\n loadConfigSync(name: string): ReturnType<Config['loadConfigSync']> {\n return this.config.loadConfigSync(name);\n }\n\n createContext<StateT = DefaultState>(\n req: IncomingMessage,\n res: ServerResponse,\n ): ParameterizedContext<StateT> {\n const ctx = super.createContext<StateT>(req, res);\n ctx.sanitizedState = {} as ContextSanitizedState;\n return ctx;\n }\n\n servePublic(): void {\n this.use(serve(this.publicPath)); // static files\n }\n\n catchErrors(): void {\n this.use(errors);\n }\n\n listen(): Server {\n throw new Error('Use start instead');\n }\n\n /**\n * Close server and emit close event\n */\n close(): void {\n if (this._server) {\n this._server.close();\n this.emit('close');\n }\n }\n\n async start(fn: () => Promise<void> | void): Promise<Server> {\n await fn();\n try {\n const server = await _listen(this.config, this.callback(), this.certPath);\n this._server = server;\n logger.success('started');\n if (process.send) process.send('ready');\n return server;\n } catch (err: unknown) {\n logger.error('start fail', { err });\n throw err;\n }\n }\n}\n\nexport type { Context } from 'koa';\n","import { existsSync, readFileSync } from 'fs';\nimport path from 'path';\nimport { Config } from 'alp-node-config';\nimport { Logger } from 'nightingale-logger';\nimport type { AlpNodeAppOptions } from './AlpNodeApp';\nimport { AlpNodeApp } from './AlpNodeApp';\n\nexport { default as fetch } from 'node-fetch';\n\nexport type { Context } from './AlpNodeApp';\nexport { Config } from 'alp-node-config';\n\nconst logger = new Logger('alp');\n\n// see alp-dev\nexport const appDirname = path.resolve('build');\n\nconst packagePath = path.resolve('package.json');\nif (!packagePath) {\n throw new Error(`Could not find package.json: \"${String(packagePath)}\"`);\n}\nexport const packageDirname = path.dirname(packagePath);\n\nlogger.debug('init', { appDirname, packageDirname });\n\nexport const packageConfig: Record<string, unknown> = JSON.parse(\n readFileSync(packagePath, 'utf-8'),\n) as Record<string, unknown>;\n\nconst buildedConfigPath = `${appDirname}/build/config/`;\nconst configPath = existsSync(buildedConfigPath)\n ? buildedConfigPath\n : `${appDirname}/config/`;\n\nexport const config = new Config(configPath).loadSync({ packageConfig });\n\nexport type AppOptions = Omit<\n AlpNodeAppOptions,\n 'appDirname' | 'packageDirname' | 'config'\n>;\n\nexport default class App extends AlpNodeApp {\n constructor(options?: AppOptions) {\n super({\n ...options,\n appDirname,\n packageDirname,\n config,\n });\n }\n}\n"],"names":["logger","Logger","AlpNodeApp","Koa","constructor","appDirname","packageDirname","config","certPath","publicPath","dirname","path","normalize","Object","defineProperty","get","deprecate","configurable","enumerable","_config","context","params","language","translate","use","compress","existsConfigSync","name","loadConfigSync","createContext","req","res","ctx","sanitizedState","servePublic","serve","catchErrors","errors","listen","Error","close","_server","emit","start","fn","server","_listen","callback","success","process","send","err","error","resolve","packagePath","String","debug","packageConfig","JSON","parse","readFileSync","buildedConfigPath","configPath","existsSync","Config","loadSync","App","options"],"mappings":";;;;;;;;;;;;;;;;AAuBA,MAAMA,QAAM,GAAG,IAAIC,MAAJ,CAAW,KAAX,CAAf;AAmBO,MAAMC,UAAN,SAAyBC,GAAzB,CAAsE;AAW3E;AACF;AACA;AACA;AACA;AACEC,EAAAA,WAAW,CAAC;AACVC,IAAAA,UADU;AAEVC,IAAAA,cAFU;AAGVC,IAAAA,MAHU;AAIVC,IAAAA,QAJU;AAKVC,IAAAA;AALU,GAAD,EAMW;AACpB;AAEA,SAAKC,OAAL,GAAeC,IAAI,CAACC,SAAL,CAAeP,UAAf,CAAf;AAEAQ,IAAAA,MAAM,CAACC,cAAP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AAMO,iBAAiB,GAAI,GAAExD,UAAW,gBAAxC;AACA,MAAMyD,UAAU,GAAGC,UAAU,CAACF,iBAAD,CAAV,GACfA,iBADe,GAEd,GAAExD,UAAW,UAFlB;MAIaE,MAAM,GAAG,IAAIyD,MAAJ,CAAWF,UAAX,EAAuBG,QAAvB,CAAgC;AAAER,EAAAA;AAAF,CAAhC;AAOP,MAAMS,GAAN,SAAkBhE,UAAlB,CAA6B;AAC1CE,EAAAA,WAAW,CAAC+D,OAAD,EAAuB;AAChC,UAAM,EACJ,GAAGA,OADC;AAEJ9D,MAAAA,UAFI;AAGJC,MAAAA,cAHI;AAIJC,MAAAA;AAJI,KAAN;AAMD;;AARyC;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Config } from 'alp-node-config';
|
|
2
|
-
import type { AlpNodeAppOptions
|
|
2
|
+
import type { AlpNodeAppOptions } from './AlpNodeApp';
|
|
3
3
|
import { AlpNodeApp } from './AlpNodeApp';
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
4
|
+
export { default as fetch } from 'node-fetch';
|
|
5
|
+
export type { Context } from './AlpNodeApp';
|
|
6
|
+
export { Config } from 'alp-node-config';
|
|
6
7
|
export declare const appDirname: string;
|
|
7
8
|
export declare const packageDirname: string;
|
|
8
9
|
export declare const packageConfig: Record<string, unknown>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAE9C,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAKzC,eAAO,MAAM,UAAU,QAAwB,CAAC;AAMhD,eAAO,MAAM,cAAc,QAA4B,CAAC;AAIxD,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAEtB,CAAC;AAO7B,eAAO,MAAM,MAAM,yCAAqD,CAAC;AAEzE,oBAAY,UAAU,GAAG,IAAI,CAC3B,iBAAiB,EACjB,YAAY,GAAG,gBAAgB,GAAG,QAAQ,CAC3C,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,UAAU;gBAC7B,OAAO,CAAC,EAAE,UAAU;CAQjC"}
|
package/fetch.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
global.fetch = require('node-fetch');
|
|
1
|
+
// eslint-disable-next-line no-restricted-exports
|
|
2
|
+
export { default } from './dist/fetch-node14.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alp-node",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "framework based on koa 2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"springbokjs",
|
|
@@ -20,52 +20,52 @@
|
|
|
20
20
|
"bugs": {
|
|
21
21
|
"url": "https://github.com/alpjs/alp-node/issues"
|
|
22
22
|
},
|
|
23
|
+
"type": "module",
|
|
23
24
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
25
|
+
"node": "^14.13.1 || >=16.0.0"
|
|
25
26
|
},
|
|
26
|
-
"main": "./index.
|
|
27
|
+
"main": "./dist/index-node14.mjs",
|
|
27
28
|
"types": "./dist/index.d.ts",
|
|
29
|
+
"typesVersions": {
|
|
30
|
+
">=3.1": {
|
|
31
|
+
"AlpNodeApp": [
|
|
32
|
+
"./dist/AlpNodeApp.d.ts"
|
|
33
|
+
],
|
|
34
|
+
"fetch": [
|
|
35
|
+
"./dist/fetch.d.ts"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
28
39
|
"exports": {
|
|
40
|
+
"./package.json": "./package.json",
|
|
29
41
|
".": {
|
|
30
42
|
"node": {
|
|
31
|
-
"
|
|
32
|
-
"import": "./dist/index-node12-dev.mjs",
|
|
33
|
-
"require": "./dist/index-node12-dev.cjs.js"
|
|
34
|
-
},
|
|
35
|
-
"import": "./dist/index-node12.mjs",
|
|
36
|
-
"require": "./dist/index-node12.cjs.js"
|
|
43
|
+
"import": "./dist/index-node14.mjs"
|
|
37
44
|
}
|
|
38
45
|
},
|
|
39
46
|
"./AlpNodeApp": {
|
|
40
47
|
"node": {
|
|
41
|
-
"
|
|
42
|
-
"import": "./dist/AlpNodeApp-node12-dev.mjs",
|
|
43
|
-
"require": "./dist/AlpNodeApp-node12-dev.cjs.js"
|
|
44
|
-
},
|
|
45
|
-
"import": "./dist/AlpNodeApp-node12.mjs",
|
|
46
|
-
"require": "./dist/AlpNodeApp-node12.cjs.js"
|
|
48
|
+
"import": "./dist/AlpNodeApp-node14.mjs"
|
|
47
49
|
}
|
|
48
50
|
},
|
|
49
51
|
"./fetch": {
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
+
"node": {
|
|
53
|
+
"import": "./dist/fetch-node14.mjs"
|
|
54
|
+
}
|
|
52
55
|
}
|
|
53
56
|
},
|
|
54
|
-
"module:node": "./dist/index-
|
|
55
|
-
"module:node-dev": "./dist/index-node12-dev.mjs",
|
|
57
|
+
"module:node": "./dist/index-node14.mjs",
|
|
56
58
|
"module:aliases-node": {
|
|
57
|
-
"./AlpNodeApp.js": "./dist/AlpNodeApp-
|
|
58
|
-
|
|
59
|
-
"module:aliases-node-dev": {
|
|
60
|
-
"./AlpNodeApp.js": "./dist/AlpNodeApp-node12-dev.es.js"
|
|
59
|
+
"./AlpNodeApp.js": "./dist/AlpNodeApp-node14.es.js",
|
|
60
|
+
"./fetch.js": "./dist/fetch-node14.es.js"
|
|
61
61
|
},
|
|
62
62
|
"sideEffects": false,
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "pob-build && yarn run build:definitions",
|
|
65
65
|
"build:definitions": "tsc -p tsconfig.build.json",
|
|
66
|
-
"clean": "rm -Rf
|
|
66
|
+
"clean": "rm -Rf dist",
|
|
67
67
|
"lint": "yarn run lint:eslint",
|
|
68
|
-
"lint:eslint": "
|
|
68
|
+
"lint:eslint": "cd ../.. && yarn run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/alp-node",
|
|
69
69
|
"watch": "pob-watch"
|
|
70
70
|
},
|
|
71
71
|
"prettier": {
|
|
@@ -77,47 +77,41 @@
|
|
|
77
77
|
"babelEnvs": [
|
|
78
78
|
{
|
|
79
79
|
"target": "node",
|
|
80
|
-
"version": "
|
|
80
|
+
"version": "14",
|
|
81
81
|
"formats": [
|
|
82
|
-
"cjs",
|
|
83
82
|
"es"
|
|
84
83
|
]
|
|
85
84
|
}
|
|
86
85
|
],
|
|
87
86
|
"entries": [
|
|
88
87
|
"index",
|
|
89
|
-
"AlpNodeApp"
|
|
90
|
-
],
|
|
91
|
-
"extraEntries": [
|
|
88
|
+
"AlpNodeApp",
|
|
92
89
|
"fetch"
|
|
93
90
|
]
|
|
94
91
|
},
|
|
95
92
|
"dependencies": {
|
|
96
93
|
"@types/koa": "^2.13.1",
|
|
97
94
|
"@types/node-fetch": "^2.5.8",
|
|
98
|
-
"alp-listen": "
|
|
99
|
-
"alp-node-config": "
|
|
100
|
-
"alp-node-errors": "
|
|
101
|
-
"alp-node-language": "
|
|
102
|
-
"alp-params": "
|
|
103
|
-
"alp-translate": "
|
|
95
|
+
"alp-listen": "5.0.0",
|
|
96
|
+
"alp-node-config": "7.0.0",
|
|
97
|
+
"alp-node-errors": "6.0.0",
|
|
98
|
+
"alp-node-language": "5.1.0",
|
|
99
|
+
"alp-params": "4.1.0",
|
|
100
|
+
"alp-translate": "6.0.1",
|
|
104
101
|
"alp-types": "^3.0.0",
|
|
105
|
-
"findup-sync": "^4.0.0",
|
|
106
102
|
"koa": "^2.13.1",
|
|
107
103
|
"koa-compress": "^5.0.0",
|
|
108
104
|
"koa-static": "^5.0.0",
|
|
109
|
-
"nightingale-logger": "^
|
|
105
|
+
"nightingale-logger": "^12.1.2",
|
|
110
106
|
"node-fetch": "^2.6.1"
|
|
111
107
|
},
|
|
112
108
|
"devDependencies": {
|
|
113
|
-
"@babel/core": "7.
|
|
114
|
-
"@types/
|
|
115
|
-
"@types/koa-
|
|
116
|
-
"@types/
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
"pob-babel": "26.8.0",
|
|
120
|
-
"rollup": "2.43.1"
|
|
109
|
+
"@babel/core": "7.16.7",
|
|
110
|
+
"@types/koa-compress": "4.0.3",
|
|
111
|
+
"@types/koa-static": "4.0.2",
|
|
112
|
+
"@types/minimist": "1.2.2",
|
|
113
|
+
"pob-babel": "29.6.1",
|
|
114
|
+
"typescript": "4.5.4"
|
|
121
115
|
},
|
|
122
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "a69797c459e219e09fcf22cc2ea46aa60dce396b"
|
|
123
117
|
}
|
package/src/.eslintrc.json
CHANGED
|
@@ -7,7 +7,24 @@
|
|
|
7
7
|
"plugins": ["@typescript-eslint"],
|
|
8
8
|
"extends": [
|
|
9
9
|
"@pob/eslint-config-typescript",
|
|
10
|
-
"@pob/eslint-config-typescript
|
|
10
|
+
"@pob/eslint-config-typescript/node"
|
|
11
11
|
],
|
|
12
|
-
"ignorePatterns": ["*.d.ts"]
|
|
12
|
+
"ignorePatterns": ["*.d.ts"],
|
|
13
|
+
"overrides": [
|
|
14
|
+
{
|
|
15
|
+
"files": ["**/*.test.ts", "__tests__/**/*.ts"],
|
|
16
|
+
"extends": ["@pob/eslint-config-typescript/test"],
|
|
17
|
+
"env": {
|
|
18
|
+
"jest": true
|
|
19
|
+
},
|
|
20
|
+
"rules": {
|
|
21
|
+
"import/no-extraneous-dependencies": [
|
|
22
|
+
"error",
|
|
23
|
+
{
|
|
24
|
+
"devDependencies": true
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
]
|
|
13
30
|
}
|
package/src/AlpNodeApp.ts
CHANGED
|
@@ -16,10 +16,10 @@ import type {
|
|
|
16
16
|
ContextSanitizedState,
|
|
17
17
|
} from 'alp-types';
|
|
18
18
|
import Koa from 'koa';
|
|
19
|
-
import type { ParameterizedContext, DefaultState
|
|
19
|
+
import type { ParameterizedContext, DefaultState } from 'koa';
|
|
20
20
|
import compress from 'koa-compress';
|
|
21
21
|
import serve from 'koa-static';
|
|
22
|
-
import Logger from 'nightingale-logger';
|
|
22
|
+
import { Logger } from 'nightingale-logger';
|
|
23
23
|
|
|
24
24
|
const logger = new Logger('alp');
|
|
25
25
|
|
|
@@ -32,13 +32,14 @@ export interface AlpNodeAppOptions {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
declare module 'koa' {
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-shadow
|
|
35
36
|
interface DefaultState extends ContextState {}
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
36
38
|
interface DefaultContext extends AlpContext {}
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
37
40
|
interface BaseContext extends AlpContext {}
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
export type { Context };
|
|
41
|
-
|
|
42
43
|
export class AlpNodeApp extends Koa<ContextState> implements NodeApplication {
|
|
43
44
|
dirname: string;
|
|
44
45
|
|
|
@@ -138,3 +139,5 @@ export class AlpNodeApp extends Koa<ContextState> implements NodeApplication {
|
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
}
|
|
142
|
+
|
|
143
|
+
export type { Context } from 'koa';
|
package/src/fetch.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import nodeFetch from 'node-fetch';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
// eslint-disable-next-line vars-on-top, no-var
|
|
5
|
+
var fetch: typeof nodeFetch;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
global.fetch = nodeFetch;
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line unicorn/prefer-export-from
|
|
11
|
+
export default nodeFetch;
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { Config } from 'alp-node-config';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import type { AlpNodeAppOptions, Context } from './AlpNodeApp';
|
|
4
|
+
import { Logger } from 'nightingale-logger';
|
|
5
|
+
import type { AlpNodeAppOptions } from './AlpNodeApp';
|
|
7
6
|
import { AlpNodeApp } from './AlpNodeApp';
|
|
8
7
|
|
|
9
|
-
export
|
|
10
|
-
|
|
8
|
+
export { default as fetch } from 'node-fetch';
|
|
9
|
+
|
|
10
|
+
export type { Context } from './AlpNodeApp';
|
|
11
|
+
export { Config } from 'alp-node-config';
|
|
11
12
|
|
|
12
13
|
const logger = new Logger('alp');
|
|
13
14
|
|
|
14
15
|
// see alp-dev
|
|
15
16
|
export const appDirname = path.resolve('build');
|
|
16
17
|
|
|
17
|
-
const packagePath =
|
|
18
|
+
const packagePath = path.resolve('package.json');
|
|
18
19
|
if (!packagePath) {
|
|
19
20
|
throw new Error(`Could not find package.json: "${String(packagePath)}"`);
|
|
20
21
|
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const util = require('util');
|
|
7
|
-
const _listen = require('alp-listen');
|
|
8
|
-
const _config = require('alp-node-config');
|
|
9
|
-
const errors = require('alp-node-errors');
|
|
10
|
-
const language = require('alp-node-language');
|
|
11
|
-
const params = require('alp-params');
|
|
12
|
-
const translate = require('alp-translate');
|
|
13
|
-
const Koa = require('koa');
|
|
14
|
-
const compress = require('koa-compress');
|
|
15
|
-
const serve = require('koa-static');
|
|
16
|
-
const Logger = require('nightingale-logger');
|
|
17
|
-
|
|
18
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
|
|
19
|
-
|
|
20
|
-
const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
21
|
-
const _listen__default = /*#__PURE__*/_interopDefaultLegacy(_listen);
|
|
22
|
-
const _config__default = /*#__PURE__*/_interopDefaultLegacy(_config);
|
|
23
|
-
const errors__default = /*#__PURE__*/_interopDefaultLegacy(errors);
|
|
24
|
-
const language__default = /*#__PURE__*/_interopDefaultLegacy(language);
|
|
25
|
-
const params__default = /*#__PURE__*/_interopDefaultLegacy(params);
|
|
26
|
-
const translate__default = /*#__PURE__*/_interopDefaultLegacy(translate);
|
|
27
|
-
const Koa__default = /*#__PURE__*/_interopDefaultLegacy(Koa);
|
|
28
|
-
const compress__default = /*#__PURE__*/_interopDefaultLegacy(compress);
|
|
29
|
-
const serve__default = /*#__PURE__*/_interopDefaultLegacy(serve);
|
|
30
|
-
const Logger__default = /*#__PURE__*/_interopDefaultLegacy(Logger);
|
|
31
|
-
|
|
32
|
-
const logger = new Logger__default('alp');
|
|
33
|
-
class AlpNodeApp extends Koa__default {
|
|
34
|
-
/**
|
|
35
|
-
* @param {Object} [options]
|
|
36
|
-
* @param {string} [options.certPath] directory of the ssl certificates
|
|
37
|
-
* @param {string} [options.publicPath] directory of public files
|
|
38
|
-
*/
|
|
39
|
-
constructor({
|
|
40
|
-
appDirname,
|
|
41
|
-
packageDirname,
|
|
42
|
-
config,
|
|
43
|
-
certPath,
|
|
44
|
-
publicPath
|
|
45
|
-
}) {
|
|
46
|
-
super();
|
|
47
|
-
this.dirname = path__default.normalize(appDirname);
|
|
48
|
-
Object.defineProperty(this, 'packageDirname', {
|
|
49
|
-
get: util.deprecate(() => packageDirname, 'packageDirname'),
|
|
50
|
-
configurable: false,
|
|
51
|
-
enumerable: false
|
|
52
|
-
});
|
|
53
|
-
this.certPath = certPath || `${packageDirname}/config/cert`;
|
|
54
|
-
this.publicPath = publicPath || `${packageDirname}/public/`;
|
|
55
|
-
this.config = _config__default(this, config);
|
|
56
|
-
this.context.config = this.config;
|
|
57
|
-
params__default(this);
|
|
58
|
-
language__default(this);
|
|
59
|
-
translate__default('locales')(this);
|
|
60
|
-
this.use(compress__default());
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
existsConfigSync(name) {
|
|
64
|
-
return this.config.existsConfigSync(name);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
loadConfigSync(name) {
|
|
68
|
-
return this.config.loadConfigSync(name);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
createContext(req, res) {
|
|
72
|
-
const ctx = super.createContext(req, res);
|
|
73
|
-
ctx.sanitizedState = {};
|
|
74
|
-
return ctx;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
servePublic() {
|
|
78
|
-
this.use(serve__default(this.publicPath)); // static files
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
catchErrors() {
|
|
82
|
-
this.use(errors__default);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
listen() {
|
|
86
|
-
throw new Error('Use start instead');
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Close server and emit close event
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
close() {
|
|
94
|
-
if (this._server) {
|
|
95
|
-
this._server.close();
|
|
96
|
-
|
|
97
|
-
this.emit('close');
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async start(fn) {
|
|
102
|
-
await fn();
|
|
103
|
-
|
|
104
|
-
try {
|
|
105
|
-
const server = await _listen__default(this.config, this.callback(), this.certPath);
|
|
106
|
-
this._server = server;
|
|
107
|
-
logger.success('started');
|
|
108
|
-
if (process.send) process.send('ready');
|
|
109
|
-
return server;
|
|
110
|
-
} catch (err) {
|
|
111
|
-
logger.error('start fail', {
|
|
112
|
-
err
|
|
113
|
-
});
|
|
114
|
-
throw err;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
exports.AlpNodeApp = AlpNodeApp;
|
|
121
|
-
//# sourceMappingURL=AlpNodeApp-node12-dev.cjs.js.map
|