alp-node 3.2.2 → 4.0.0

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.
@@ -1,103 +0,0 @@
1
- import path from 'path';
2
- import { deprecate } from 'util';
3
- import _listen from 'alp-listen';
4
- import _config from 'alp-node-config';
5
- import errors from 'alp-node-errors';
6
- import language from 'alp-node-language';
7
- import params from 'alp-params';
8
- import translate from 'alp-translate';
9
- import Koa from 'koa';
10
- import compress from 'koa-compress';
11
- import serve from 'koa-static';
12
- import Logger from 'nightingale-logger';
13
-
14
- const logger = new Logger('alp');
15
- class AlpNodeApp extends Koa {
16
- /**
17
- * @param {Object} [options]
18
- * @param {string} [options.certPath] directory of the ssl certificates
19
- * @param {string} [options.publicPath] directory of public files
20
- */
21
- constructor({
22
- appDirname,
23
- packageDirname,
24
- config,
25
- certPath,
26
- publicPath
27
- }) {
28
- super();
29
- this.dirname = path.normalize(appDirname);
30
- Object.defineProperty(this, 'packageDirname', {
31
- get: deprecate(() => packageDirname, 'packageDirname'),
32
- configurable: false,
33
- enumerable: false
34
- });
35
- this.certPath = certPath || `${packageDirname}/config/cert`;
36
- this.publicPath = publicPath || `${packageDirname}/public/`;
37
- this.config = _config(this, config);
38
- this.context.config = this.config;
39
- params(this);
40
- language(this);
41
- translate('locales')(this);
42
- this.use(compress());
43
- }
44
-
45
- existsConfigSync(name) {
46
- return this.config.existsConfigSync(name);
47
- }
48
-
49
- loadConfigSync(name) {
50
- return this.config.loadConfigSync(name);
51
- }
52
-
53
- createContext(req, res) {
54
- const ctx = super.createContext(req, res);
55
- ctx.sanitizedState = {};
56
- return ctx;
57
- }
58
-
59
- servePublic() {
60
- this.use(serve(this.publicPath)); // static files
61
- }
62
-
63
- catchErrors() {
64
- this.use(errors);
65
- }
66
-
67
- listen() {
68
- throw new Error('Use start instead');
69
- }
70
- /**
71
- * Close server and emit close event
72
- */
73
-
74
-
75
- close() {
76
- if (this._server) {
77
- this._server.close();
78
-
79
- this.emit('close');
80
- }
81
- }
82
-
83
- async start(fn) {
84
- await fn();
85
-
86
- try {
87
- const server = await _listen(this.config, this.callback(), this.certPath);
88
- this._server = server;
89
- logger.success('started');
90
- if (process.send) process.send('ready');
91
- return server;
92
- } catch (err) {
93
- logger.error('start fail', {
94
- err
95
- });
96
- throw err;
97
- }
98
- }
99
-
100
- }
101
-
102
- export { AlpNodeApp };
103
- //# sourceMappingURL=AlpNodeApp-node12-dev.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AlpNodeApp-node12-dev.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, Context } 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 interface DefaultState extends ContextState {}\n interface DefaultContext extends AlpContext {}\n interface BaseContext extends AlpContext {}\n}\n\nexport type { Context };\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"],"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;AAkBO,MAAMC,UAAN,SAAyBC,GA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AACAC,IAAAA,GAAG,CAACC,cAAJ,GAAqB,EAArB;AACA,WAAOD,GAAP;AACD;;AAEDE,EAAAA,WAAW,GAAS;AAClB,SAAKV,GAAL,CAASW,KAAK,CAAC,KAAK1B,UAAN,CAAd,EADkB;AAEnB;;AAED2B,EAAAA,WAAW,GAAS;AAClB,SAAKZ,GAAL,CAASa,MAAT;AACD;;AAEDC,EAAAA,MAAM,GAAW;AACf,UAAM,IAAIC,KAAJ,CAAU,mBAAV,CAAN;AACD;AAED;AACF;AACA;;;AACEC,EAAAA,KAAK,GAAS;AACZ,QAAI,KAAKC,OAAT,EAAkB;AAChB,WAAKA,OAAL,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;;;;"}
@@ -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.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AlpNodeApp-node12.cjs.js","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, Context } 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 interface DefaultState extends ContextState {}\n interface DefaultContext extends AlpContext {}\n interface BaseContext extends AlpContext {}\n}\n\nexport type { Context };\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"],"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,eAAJ,CAAW,KAAX,CAAf;AAkBO,MAAMC,UAAN,SAAyBC,YAAzB,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,aAAI,CAACC,SAAL,CAAeP,UAAf,CAAf;AAEAQ,IAAAA,MAAM,CAACC,cAAP,CAAsB,IAAtB,EAA4B,gBAA5B,EAA8C;AAC5CC,MAAAA,GAAG,EAAEC,cAAS,CAAC,MAAMV,cAAP,EAAuB,gBAAvB,CAD8B;AAE5CW,MAAAA,YAAY,EAAE,KAF8B;AAG5CC,MAAAA,UAAU,EAAE;AAHgC,KAA9C;AAMA,SAAKV,QAAL,GAAgBA,QAAQ,IAAK,GAAEF,cAAe,cAA9C;AACA,SAAKG,UAAL,GAAkBA,UAAU,IAAK,GAAEH,cAAe,UAAlD;AAEA,SAAKC,MAAL,GAAcY,gBAAO,CAAC,IAAD,EAAOZ,MAAP,CAArB;AACA,SAAKa,OAAL,CAAab,MAAb,GAAsB,KAAKA,MAA3B;AAEAc,IAAAA,eAAM,CAAC,IAAD,CAAN;AACAC,IAAAA,iBAAQ,CAAC,IAAD,CAAR;AACAC,IAAAA,kBAAS,CAAC,SAAD,CAAT,CAAqB,IAArB;AAEA,SAAKC,GAAL,CAASC,iBAAQ,EAAjB;AACD;;AAEDC,EAAAA,gBAAgB,CAACC,IAAD,EAAuD;AACrE,WAAO,KAAKpB,MAAL,C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AACD;AACF;;AAjG0E;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AlpNodeApp-node12.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, Context } 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 interface DefaultState extends ContextState {}\n interface DefaultContext extends AlpContext {}\n interface BaseContext extends AlpContext {}\n}\n\nexport type { Context };\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"],"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;AAkBO,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,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AAM,IAAIC,KAAJ,CAAU,mBAAV,CAAN;AACD;AAED;AACF;AACA;;;AACEC,EAAAA,KAAK,GAAS;AACZ,QAAI,KAAKC,OAAT,EAAkB;AAChB,WAAKA,OAAL,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;;;;"}
@@ -1,162 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
- const _config = require('alp-node-config');
8
- const findUp = require('findup-sync');
9
- const Logger = require('nightingale-logger');
10
- const util = require('util');
11
- const _listen = require('alp-listen');
12
- const errors = require('alp-node-errors');
13
- const language = require('alp-node-language');
14
- const params = require('alp-params');
15
- const translate = require('alp-translate');
16
- const Koa = require('koa');
17
- const compress = require('koa-compress');
18
- const serve = require('koa-static');
19
-
20
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
21
-
22
- const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
23
- const _config__default = /*#__PURE__*/_interopDefaultLegacy(_config);
24
- const findUp__default = /*#__PURE__*/_interopDefaultLegacy(findUp);
25
- const Logger__default = /*#__PURE__*/_interopDefaultLegacy(Logger);
26
- const _listen__default = /*#__PURE__*/_interopDefaultLegacy(_listen);
27
- const errors__default = /*#__PURE__*/_interopDefaultLegacy(errors);
28
- const language__default = /*#__PURE__*/_interopDefaultLegacy(language);
29
- const params__default = /*#__PURE__*/_interopDefaultLegacy(params);
30
- const translate__default = /*#__PURE__*/_interopDefaultLegacy(translate);
31
- const Koa__default = /*#__PURE__*/_interopDefaultLegacy(Koa);
32
- const compress__default = /*#__PURE__*/_interopDefaultLegacy(compress);
33
- const serve__default = /*#__PURE__*/_interopDefaultLegacy(serve);
34
-
35
- const logger$1 = new Logger__default('alp');
36
- class AlpNodeApp extends Koa__default {
37
- /**
38
- * @param {Object} [options]
39
- * @param {string} [options.certPath] directory of the ssl certificates
40
- * @param {string} [options.publicPath] directory of public files
41
- */
42
- constructor({
43
- appDirname,
44
- packageDirname,
45
- config,
46
- certPath,
47
- publicPath
48
- }) {
49
- super();
50
- this.dirname = path__default.normalize(appDirname);
51
- Object.defineProperty(this, 'packageDirname', {
52
- get: util.deprecate(() => packageDirname, 'packageDirname'),
53
- configurable: false,
54
- enumerable: false
55
- });
56
- this.certPath = certPath || `${packageDirname}/config/cert`;
57
- this.publicPath = publicPath || `${packageDirname}/public/`;
58
- this.config = _config__default(this, config);
59
- this.context.config = this.config;
60
- params__default(this);
61
- language__default(this);
62
- translate__default('locales')(this);
63
- this.use(compress__default());
64
- }
65
-
66
- existsConfigSync(name) {
67
- return this.config.existsConfigSync(name);
68
- }
69
-
70
- loadConfigSync(name) {
71
- return this.config.loadConfigSync(name);
72
- }
73
-
74
- createContext(req, res) {
75
- const ctx = super.createContext(req, res);
76
- ctx.sanitizedState = {};
77
- return ctx;
78
- }
79
-
80
- servePublic() {
81
- this.use(serve__default(this.publicPath)); // static files
82
- }
83
-
84
- catchErrors() {
85
- this.use(errors__default);
86
- }
87
-
88
- listen() {
89
- throw new Error('Use start instead');
90
- }
91
- /**
92
- * Close server and emit close event
93
- */
94
-
95
-
96
- close() {
97
- if (this._server) {
98
- this._server.close();
99
-
100
- this.emit('close');
101
- }
102
- }
103
-
104
- async start(fn) {
105
- await fn();
106
-
107
- try {
108
- const server = await _listen__default(this.config, this.callback(), this.certPath);
109
- this._server = server;
110
- logger$1.success('started');
111
- if (process.send) process.send('ready');
112
- return server;
113
- } catch (err) {
114
- logger$1.error('start fail', {
115
- err
116
- });
117
- throw err;
118
- }
119
- }
120
-
121
- }
122
-
123
- const logger = new Logger__default('alp'); // see alp-dev
124
-
125
- const appDirname = path__default.resolve('build');
126
- const packagePath = findUp__default('package.json', {
127
- cwd: appDirname
128
- });
129
-
130
- if (!packagePath) {
131
- throw new Error(`Could not find package.json: "${String(packagePath)}"`);
132
- }
133
-
134
- const packageDirname = path__default.dirname(packagePath);
135
- logger.debug('init', {
136
- appDirname,
137
- packageDirname
138
- });
139
- const packageConfig = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
140
- const buildedConfigPath = `${appDirname}/build/config/`;
141
- const configPath = fs.existsSync(buildedConfigPath) ? buildedConfigPath : `${appDirname}/config/`;
142
- const config = new _config.Config(configPath).loadSync({
143
- packageConfig
144
- });
145
- class App extends AlpNodeApp {
146
- constructor(options) {
147
- super({ ...options,
148
- appDirname,
149
- packageDirname,
150
- config
151
- });
152
- }
153
-
154
- }
155
-
156
- exports.Config = _config.Config;
157
- exports.appDirname = appDirname;
158
- exports.config = config;
159
- exports.default = App;
160
- exports.packageConfig = packageConfig;
161
- exports.packageDirname = packageDirname;
162
- //# sourceMappingURL=index-node12-dev.cjs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-node12-dev.cjs.js","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, Context } 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 interface DefaultState extends ContextState {}\n interface DefaultContext extends AlpContext {}\n interface BaseContext extends AlpContext {}\n}\n\nexport type { Context };\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","import { existsSync, readFileSync } from 'fs';\nimport path from 'path';\nimport { Config } from 'alp-node-config';\nimport findUp from 'findup-sync';\nimport Logger from 'nightingale-logger';\nimport type { AlpNodeAppOptions, Context } from './AlpNodeApp';\nimport { AlpNodeApp } from './AlpNodeApp';\n\nexport type { Context };\nexport { Config };\n\nconst logger = new Logger('alp');\n\n// see alp-dev\nexport const appDirname = path.resolve('build');\n\nconst packagePath = findUp('package.json', { cwd: appDirname });\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","findUp","cwd","String","debug","packageConfig","JSON","parse","readFileSync","buildedConfigPath","configPath","existsSync","Config","loadSync","App","options"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAMA,QAAM,GAAG,IAAIC,eAAJ,CAAW,KAAX,CAAf;AAkBO,MAAMC,UAAN,SAAyBC,YAAzB,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,aAAI,CAACC,SAAL,CAAeP,UAAf,CAAf;AAEAQ,IAAAA,MAAM,CAACC,cAAP,CAAsB,IAAtB,EAA4B,gBAA5B,EAA8C;AAC5CC,MAAAA,GAAG,EAAEC,cAAS,CAAC,MAAMV,cAAP,EAAuB,gBAAvB,CAD8B;AAE5CW,MAAAA,YAAY,EAAE,KAF8B;AAG5CC,MAAAA,UAAU,EAAE;AAHgC,KAA9C;AAMA,SAAKV,QAAL,GAAgBA,QAAQ,IAAK,GAAEF,cAAe,cAA9C;AACA,SAAKG,UAAL,GAAkBA,UAAU,IAAK,GAAEH,cAAe,UAAlD;AAEA,SAAKC,MAAL,GAAcY,gBAAO,CAAC,IAAD,EAAOZ,MAAP,CAArB;AACA,SAAKa,OAAL,CAAab,MAAb,GAAsB,KAAKA,MAA3B;AAEAc,IAAAA,eAAM,CAAC,IAAD,CAAN;AACAC,IAAAA,iBAAQ,CAAC,IAAD,CAAR;AACAC,IAAAA,kBAAS,CAAC,SAAD,CAAT,CAAqB,IAArB;AAEA,SAAKC,GAAL,CAASC,iBAAQ,EAAjB;AACD;;AAEDC,EAA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,YAAb,EAA2B;AAAED,QAAAA;AAAF,OAA3B;AACA,YAAMA,GAAN;AACD;AACF;;AAjG0E;;AC9B7E,MAAMnD,MAAM,GAAG,IAAIC,eAAJ,CAAW,KAAX,CAAf;;MAGaI,UAAU,GAAGM,aAAI,CAAC0C,OAAL,CAAa,OAAb;AAE1B,MAAMC,WAAW,GAAGC,eAAM,CAAC,cAAD,EAAiB;AAAEC,EAAAA,GAAG,EAAEnD;AAAP,CAAjB,CAA1B;;AACA,IAAI,CAACiD,WAAL,EAAkB;AAChB,QAAM,IAAIf,KAAJ,CAAW,iCAAgCkB,MAAM,CAACH,WAAD,CAAc,GAA/D,CAAN;AACD;;MACYhD,cAAc,GAAGK,aAAI,CAACD,OAAL,CAAa4C,WAAb;AAE9BtD,MAAM,CAAC0D,KAAP,CAAa,MAAb,EAAqB;AAAErD,EAAAA,UAAF;AAAcC,EAAAA;AAAd,CAArB;MAEaqD,aAAsC,GAAGC,IAAI,CAACC,KAAL,CACpDC,eAAY,CAACR,WAAD,EAAc,OAAd,CADwC;AAItD,MAAMS,iBAAiB,GAAI,GAAE1D,UAAW,gBAAxC;AACA,MAAM2D,UAAU,GAAGC,aAAU,CAACF,iBAAD,CAAV,GACfA,iBADe,GAEd,GAAE1D,UAAW,UAFlB;MAIaE,MAAM,GAAG,IAAI2D,cAAJ,CAAWF,UAAX,EAAuBG,QAAvB,CAAgC;AAAER,EAAAA;AAAF,CAAhC;AAOP,MAAMS,GAAN,SAAkBlE,UAAlB,CAA6B;AAC1CE,EAAAA,WAAW,CAACiE,OAAD,EAAuB;AAChC,UAAM,EACJ,GAAGA,OADC;AAEJhE,MAAAA,UAFI;AAGJC,MAAAA,cAHI;AAIJC,MAAAA;AAJI,KAAN;AAMD;;AARyC;;;;;;;;;"}
@@ -1,140 +0,0 @@
1
- import { readFileSync, existsSync } from 'fs';
2
- import path from 'path';
3
- import _config, { Config } from 'alp-node-config';
4
- export { Config } from 'alp-node-config';
5
- import findUp from 'findup-sync';
6
- import Logger from 'nightingale-logger';
7
- import { deprecate } from 'util';
8
- import _listen from 'alp-listen';
9
- import errors from 'alp-node-errors';
10
- import language from 'alp-node-language';
11
- import params from 'alp-params';
12
- import translate from 'alp-translate';
13
- import Koa from 'koa';
14
- import compress from 'koa-compress';
15
- import serve from 'koa-static';
16
-
17
- const logger$1 = new Logger('alp');
18
- class AlpNodeApp extends Koa {
19
- /**
20
- * @param {Object} [options]
21
- * @param {string} [options.certPath] directory of the ssl certificates
22
- * @param {string} [options.publicPath] directory of public files
23
- */
24
- constructor({
25
- appDirname,
26
- packageDirname,
27
- config,
28
- certPath,
29
- publicPath
30
- }) {
31
- super();
32
- this.dirname = path.normalize(appDirname);
33
- Object.defineProperty(this, 'packageDirname', {
34
- get: deprecate(() => packageDirname, 'packageDirname'),
35
- configurable: false,
36
- enumerable: false
37
- });
38
- this.certPath = certPath || `${packageDirname}/config/cert`;
39
- this.publicPath = publicPath || `${packageDirname}/public/`;
40
- this.config = _config(this, config);
41
- this.context.config = this.config;
42
- params(this);
43
- language(this);
44
- translate('locales')(this);
45
- this.use(compress());
46
- }
47
-
48
- existsConfigSync(name) {
49
- return this.config.existsConfigSync(name);
50
- }
51
-
52
- loadConfigSync(name) {
53
- return this.config.loadConfigSync(name);
54
- }
55
-
56
- createContext(req, res) {
57
- const ctx = super.createContext(req, res);
58
- ctx.sanitizedState = {};
59
- return ctx;
60
- }
61
-
62
- servePublic() {
63
- this.use(serve(this.publicPath)); // static files
64
- }
65
-
66
- catchErrors() {
67
- this.use(errors);
68
- }
69
-
70
- listen() {
71
- throw new Error('Use start instead');
72
- }
73
- /**
74
- * Close server and emit close event
75
- */
76
-
77
-
78
- close() {
79
- if (this._server) {
80
- this._server.close();
81
-
82
- this.emit('close');
83
- }
84
- }
85
-
86
- async start(fn) {
87
- await fn();
88
-
89
- try {
90
- const server = await _listen(this.config, this.callback(), this.certPath);
91
- this._server = server;
92
- logger$1.success('started');
93
- if (process.send) process.send('ready');
94
- return server;
95
- } catch (err) {
96
- logger$1.error('start fail', {
97
- err
98
- });
99
- throw err;
100
- }
101
- }
102
-
103
- }
104
-
105
- const logger = new Logger('alp'); // see alp-dev
106
-
107
- const appDirname = path.resolve('build');
108
- const packagePath = findUp('package.json', {
109
- cwd: appDirname
110
- });
111
-
112
- if (!packagePath) {
113
- throw new Error(`Could not find package.json: "${String(packagePath)}"`);
114
- }
115
-
116
- const packageDirname = path.dirname(packagePath);
117
- logger.debug('init', {
118
- appDirname,
119
- packageDirname
120
- });
121
- const packageConfig = JSON.parse(readFileSync(packagePath, 'utf-8'));
122
- const buildedConfigPath = `${appDirname}/build/config/`;
123
- const configPath = existsSync(buildedConfigPath) ? buildedConfigPath : `${appDirname}/config/`;
124
- const config = new Config(configPath).loadSync({
125
- packageConfig
126
- });
127
- class App extends AlpNodeApp {
128
- constructor(options) {
129
- super({ ...options,
130
- appDirname,
131
- packageDirname,
132
- config
133
- });
134
- }
135
-
136
- }
137
-
138
- export default App;
139
- export { appDirname, config, packageConfig, packageDirname };
140
- //# sourceMappingURL=index-node12-dev.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-node12-dev.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, Context } 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 interface DefaultState extends ContextState {}\n interface DefaultContext extends AlpContext {}\n interface BaseContext extends AlpContext {}\n}\n\nexport type { Context };\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","import { existsSync, readFileSync } from 'fs';\nimport path from 'path';\nimport { Config } from 'alp-node-config';\nimport findUp from 'findup-sync';\nimport Logger from 'nightingale-logger';\nimport type { AlpNodeAppOptions, Context } from './AlpNodeApp';\nimport { AlpNodeApp } from './AlpNodeApp';\n\nexport type { Context };\nexport { Config };\n\nconst logger = new Logger('alp');\n\n// see alp-dev\nexport const appDirname = path.resolve('build');\n\nconst packagePath = findUp('package.json', { cwd: appDirname });\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","findUp","cwd","String","debug","packageConfig","JSON","parse","readFileSync","buildedConfigPath","configPath","existsSync","Config","loadSync","App","options"],"mappings":";;;;;;;;;;;;;;;;AAuBA,MAAMA,QAAM,GAAG,IAAIC,MAAJ,CAAW,KAAX,CAAf;AAkBO,MAAMC,UAAN,SAAyBC,GAAzB,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