@pxp-nd/core 1.2.74 → 1.2.75

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.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/dist/PxpApp.d.ts +54 -54
  3. package/dist/PxpApp.js +283 -284
  4. package/dist/ScriptManager.d.ts +1 -1
  5. package/dist/ScriptManager.js +130 -130
  6. package/dist/database/script.d.ts +16 -16
  7. package/dist/database/script.js +143 -143
  8. package/dist/db.datasource.d.ts +2 -2
  9. package/dist/db.datasource.js +86 -86
  10. package/dist/entities/Log.d.ts +32 -32
  11. package/dist/entities/Log.js +95 -95
  12. package/dist/entities/ScriptVersion.d.ts +19 -19
  13. package/dist/entities/ScriptVersion.js +43 -43
  14. package/dist/index.d.ts +11 -11
  15. package/dist/index.js +28 -28
  16. package/dist/interfaces.d.ts +49 -49
  17. package/dist/interfaces.js +3 -3
  18. package/dist/lib/pxp/Controller.d.ts +51 -51
  19. package/dist/lib/pxp/Controller.js +377 -377
  20. package/dist/lib/pxp/ControllerInterface.d.ts +18 -18
  21. package/dist/lib/pxp/ControllerInterface.js +2 -2
  22. package/dist/lib/pxp/Decorators.d.ts +23 -23
  23. package/dist/lib/pxp/Decorators.js +123 -123
  24. package/dist/lib/pxp/ListParamInterface.d.ts +23 -23
  25. package/dist/lib/pxp/ListParamInterface.js +2 -2
  26. package/dist/lib/pxp/PxpError.d.ts +24 -24
  27. package/dist/lib/pxp/PxpError.js +57 -57
  28. package/dist/lib/pxp/RouteDefinition.d.ts +26 -26
  29. package/dist/lib/pxp/RouteDefinition.js +26 -26
  30. package/dist/lib/pxp/index.d.ts +20 -20
  31. package/dist/lib/pxp/index.js +33 -33
  32. package/dist/lib/pxp/loadControllers.d.ts +4 -4
  33. package/dist/lib/pxp/loadControllers.js +89 -89
  34. package/dist/lib/pxp/middlewares/ParseParams.d.ts +4 -4
  35. package/dist/lib/pxp/middlewares/ParseParams.js +71 -71
  36. package/dist/lib/pxp/middlewares/isReportMiddleware.d.ts +2 -2
  37. package/dist/lib/pxp/middlewares/isReportMiddleware.js +13 -13
  38. package/dist/lib/pxp/utils/Security.d.ts +23 -23
  39. package/dist/lib/pxp/utils/Security.js +79 -77
  40. package/dist/lib/pxp/utils/crypto.d.ts +3 -3
  41. package/dist/lib/pxp/utils/crypto.js +15 -15
  42. package/dist/lib/reports/fonts/Roboto-Regular-normal.d.ts +2 -2
  43. package/dist/lib/reports/fonts/Roboto-Regular-normal.js +4 -4
  44. package/dist/lib/reports/generated.d.ts +4 -4
  45. package/dist/lib/reports/generated.js +200 -200
  46. package/dist/lib/reports/helper.d.ts +8 -8
  47. package/dist/lib/reports/helper.js +49 -49
  48. package/dist/lib/reports/pdf.d.ts +3 -3
  49. package/dist/lib/reports/pdf.js +119 -119
  50. package/dist/lib/reports/report-routes.d.ts +3 -3
  51. package/dist/lib/reports/report-routes.js +24 -24
  52. package/dist/lib/reports/xlsx.d.ts +1 -1
  53. package/dist/lib/reports/xlsx.js +65 -65
  54. package/dist/sockets/basic-sockets.d.ts +5 -5
  55. package/dist/sockets/basic-sockets.js +38 -38
  56. package/dist/sockets/entities/UserIo.d.ts +6 -6
  57. package/dist/sockets/entities/UserIo.js +30 -30
  58. package/dist/sockets/entities/index.d.ts +5 -5
  59. package/dist/sockets/entities/index.js +9 -9
  60. package/dist/sockets/index.d.ts +2 -2
  61. package/dist/sockets/index.js +19 -19
  62. package/dist/sockets/pxp-io-server.d.ts +6 -6
  63. package/dist/sockets/pxp-io-server.js +50 -50
  64. package/dist/swaggerOptions.d.ts +16 -16
  65. package/dist/swaggerOptions.js +20 -20
  66. package/package.json +65 -65
  67. package/yalc.lock +9 -9
package/dist/PxpApp.js CHANGED
@@ -1,284 +1,283 @@
1
- "use strict";
2
- /**
3
- * Kplian Ltda 2020
4
- *
5
- * MIT
6
- *
7
- * Main pxp-nd file.
8
- *
9
- * @summary Handles all requests for pxp-ui or pxp-nd.
10
- * @author Jaime Rivera
11
- *
12
- * Created at : 2020-06-13 18:09:48
13
- * Last modified : 2020-09-20 18:24:45
14
- */
15
- var __importDefault = (this && this.__importDefault) || function (mod) {
16
- return (mod && mod.__esModule) ? mod : { "default": mod };
17
- };
18
- Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.PxpApp = void 0;
20
- require("reflect-metadata");
21
- const typeorm_1 = require("typeorm");
22
- const express_fileupload_1 = __importDefault(require("express-fileupload"));
23
- const express_1 = __importDefault(require("express"));
24
- const passport_1 = __importDefault(require("passport"));
25
- const express_session_1 = __importDefault(require("express-session"));
26
- const typeorm_2 = require("typeorm");
27
- const cors_1 = __importDefault(require("cors"));
28
- const fs_1 = __importDefault(require("fs"));
29
- const path_1 = __importDefault(require("path"));
30
- const http_1 = __importDefault(require("http"));
31
- /** swagger options **/
32
- const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
33
- const swagger_jsdoc_1 = __importDefault(require("swagger-jsdoc"));
34
- const swaggerOptions_1 = __importDefault(require("./swaggerOptions"));
35
- const loadControllers_1 = __importDefault(require("./lib/pxp/loadControllers"));
36
- const pxp_1 = require("./lib/pxp");
37
- // import { getAuthRoutes, customAuthRoutes } from '@pxp-nd/auth';
38
- // import { configPassport } from '@pxp-nd/auth';
39
- // import { Session } from '@pxp-nd/entities';
40
- const typeorm_store_1 = require("typeorm-store");
41
- const report_routes_1 = require("./lib/reports/report-routes");
42
- const pxp_io_server_1 = __importDefault(require("./sockets/pxp-io-server"));
43
- const modulesPxp = {
44
- auth: '@pxp-nd/auth',
45
- common: '@pxp-nd/common',
46
- reports: '@pxp-nd/reports',
47
- };
48
- //auth configure
49
- /**
50
- *
51
- * */
52
- class PxpApp {
53
- constructor(config) {
54
- this.configAuth = null;
55
- this.Report = null;
56
- this.ReportGroup = null;
57
- this.sockets = {};
58
- this.config = {
59
- defaultDbSettings: 'Orm',
60
- apiPrefix: '/api',
61
- logDuration: true,
62
- middlewares: [],
63
- };
64
- this.getDurationInMilliseconds = (start) => {
65
- const NS_PER_SEC = 1e9;
66
- const NS_TO_MS = 1e6;
67
- const diff = process.hrtime(start);
68
- return (diff[0] * NS_PER_SEC + diff[1]) / NS_TO_MS;
69
- };
70
- this.folderModulesCreate();
71
- this.config = Object.assign(Object.assign({}, this.config), config);
72
- this.app = express_1.default();
73
- this.controllers = [];
74
- // this.initializeMiddlewares();
75
- }
76
- static get instance() {
77
- return this._instance || (this._instance = new this(null));
78
- }
79
- set ConfigAuth(authOptions) {
80
- this.configAuth = authOptions;
81
- }
82
- initializeSwagger() {
83
- const options = {
84
- customCss: '.swagger-ui .topbar { display: none }',
85
- explorer: true,
86
- };
87
- const swaggerDocs = swagger_jsdoc_1.default(swaggerOptions_1.default);
88
- this.app.use('/explorer', swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(swaggerDocs, options));
89
- }
90
- async loadControllers() {
91
- // await this.connectToTheDatabase();
92
- // await this.initializeAuthentication();
93
- this.controllers = await loadControllers_1.default(this.config, this.io);
94
- this.initializeRoutes();
95
- this.initializeErrorHandling();
96
- }
97
- loadIOserver() {
98
- this._httpServer = new http_1.default.Server(this.app);
99
- if (this.config.enableSocket) {
100
- this.io = new pxp_io_server_1.default(this._httpServer, this.sockets).io;
101
- }
102
- }
103
- listen() {
104
- this._httpServer.listen(process.env.PORT, () => {
105
- console.log(`${'\x1b[36m'}App listening on the port ${process.env.PORT}${'\x1b[0m'}`);
106
- });
107
- }
108
- getServer() {
109
- return this.app;
110
- }
111
- initializeMiddlewares() {
112
- this.app.use((req, res, next) => {
113
- req.start = new Date();
114
- if (this.config.logDuration) {
115
- console.log(`${req.method} ${req.originalUrl} [STARTED]`);
116
- const start = process.hrtime();
117
- res.on('finish', () => {
118
- const durationInMilliseconds = this.getDurationInMilliseconds(start);
119
- console.log(`${req.method} ${req.originalUrl} [FINISHED] ${durationInMilliseconds.toLocaleString()} ms`);
120
- });
121
- res.on('close', () => {
122
- const durationInMilliseconds = this.getDurationInMilliseconds(start);
123
- console.log(`${req.method} ${req.originalUrl} [CLOSED] ${durationInMilliseconds.toLocaleString()} ms`);
124
- });
125
- }
126
- next();
127
- });
128
- this.app.use(express_1.default.json({ limit: '2mb' }));
129
- this.app.use(express_1.default.urlencoded({ limit: '2mb' }));
130
- console.log('llegggga aca nuevo');
131
- this.app.use(express_fileupload_1.default({
132
- limits: { fileSize: 5 * 1024 * 1024 },
133
- }));
134
- this.configCors();
135
- }
136
- async initializeAuthentication(configAuth) {
137
- if (configAuth) {
138
- const { configPassport, getAuthRoutes, customAuthRoutes } = configAuth();
139
- this.initializeSession();
140
- await this.initializePassport(configPassport, getAuthRoutes, customAuthRoutes);
141
- }
142
- else {
143
- throw new Error(`Invalid config Auth, set ConfigAuth:\n
144
- \t// App.ts file
145
- \timport { configAuth } from '@pxp-nd/auth';
146
- \t// In constructror set...
147
- \tthis.ConfigAuth = configAuth;
148
- \t//...`);
149
- }
150
- }
151
- initializeErrorHandling() {
152
- this.app.use(pxp_1.errorMiddleware);
153
- }
154
- async initializePassport(configPassport, getAuthRoutes, customAuthRoutes) {
155
- configPassport(this.config.auth);
156
- this.app.use(passport_1.default.initialize());
157
- // @todo only validate session if authorization is not set(10/03/2021)
158
- this.app.use(passport_1.default.session());
159
- this.app.use((req, res, next) => {
160
- if (req.headers.authorization) {
161
- passport_1.default.authenticate('jwt', { session: false }, function (err, user, info) {
162
- if (user) {
163
- req.logIn(user, function (err) {
164
- next();
165
- });
166
- }
167
- else {
168
- next();
169
- }
170
- })(req, res, next);
171
- }
172
- else {
173
- next();
174
- }
175
- });
176
- this.app.use((req, res, next) => {
177
- next();
178
- });
179
- const routes = await customAuthRoutes();
180
- routes.forEach((route) => this.app.use(route.router));
181
- const authRoutes = getAuthRoutes(this.config.apiPrefix);
182
- this.showRoutes(authRoutes);
183
- this.app.use(authRoutes);
184
- if (this.config.reports) {
185
- if (!this.Report && !this.ReportGroup) {
186
- throw new Error(`Invalid Report configuration, set Report and ReportGroup entities:\n
187
- \t// App.ts file
188
- \timport { Report, ReportGroup } from '@pxp-nd/common';
189
- \t//...
190
- \tthis.Report = Report;
191
- \tthis.ReportGroup = ReportGroup;
192
- `);
193
- }
194
- const reportRouter = report_routes_1.getReportsRouter(this.config, this.Report, this.ReportGroup);
195
- this.showRoutes(reportRouter);
196
- this.app.use(reportRouter);
197
- }
198
- }
199
- configCors() {
200
- const whitelist = process.env.WHITE_LIST ? String(process.env.WHITE_LIST).split(',') : [];
201
- const corsOptions = {
202
- credentials: true,
203
- origin: function (origin, callback) {
204
- if (whitelist.indexOf(origin) !== -1 || !origin) {
205
- callback(null, true);
206
- }
207
- else {
208
- callback(new Error('Not allowed by CORS'));
209
- }
210
- }
211
- };
212
- this.app.use(cors_1.default(corsOptions));
213
- this.app.options('*', cors_1.default());
214
- }
215
- initializeSession() {
216
- const repository = typeorm_2.getConnection().getRepository(this.config.session);
217
- this.app.use(express_session_1.default({
218
- secret: String(process.env.SECRET),
219
- resave: false,
220
- saveUninitialized: true,
221
- store: new typeorm_store_1.TypeormStore({ repository }),
222
- cookie: {
223
- maxAge: 1000 * 60 * 60 * 168
224
- // 24 = 1 day <=> 168 = 7 days
225
- // Equals 1 day (1 day * 24 hr/1 day * 60 min/1 hr * 60 sec/1 min * 1000 ms / 1 sec)
226
- }
227
- }));
228
- }
229
- initializeRoutes() {
230
- this.controllers.forEach((controller) => {
231
- this.app.use(controller.router);
232
- this.showRoutes(controller.router);
233
- });
234
- this.app.all('*', function (req, res) {
235
- res.status(404).json({
236
- error: {
237
- code: 404,
238
- message: 'Route not found'
239
- }
240
- });
241
- });
242
- }
243
- // Show routes with config.showRoutes is true
244
- showRoutes(router) {
245
- const routes = router.stack.filter((r) => r.route)
246
- .map((r) => {
247
- return {
248
- method: Object.keys(r.route.methods)[0].toUpperCase(),
249
- path: r.route.path
250
- };
251
- });
252
- if (this.config.showRoutes) {
253
- routes.forEach((route) => console.log(`${'\x1b[31m'}${route.method.toUpperCase()}:\t${'\x1b[32m'}${route.path}${'\x1b[0m'}`));
254
- console.log('');
255
- }
256
- }
257
- async connectDatabase() {
258
- await typeorm_1.createConnections();
259
- }
260
- async run() {
261
- this.initializeSwagger();
262
- this.initializeMiddlewares();
263
- await this.connectDatabase();
264
- // configure auth options
265
- if (this.config.auth) {
266
- await this.initializeAuthentication(this.configAuth);
267
- }
268
- // load ioServer
269
- this.loadIOserver();
270
- // load controllers and routes
271
- await this.loadControllers();
272
- }
273
- folderModulesCreate() {
274
- const dirModules = path_1.default.join(process.cwd(), 'dist/modules');
275
- const dirModulesSrc = path_1.default.join(process.cwd(), 'src/modules');
276
- if (!fs_1.default.existsSync(dirModules)) {
277
- fs_1.default.mkdirSync(dirModules, '0744');
278
- }
279
- if (!fs_1.default.existsSync(dirModulesSrc)) {
280
- fs_1.default.mkdirSync(dirModulesSrc, '0744');
281
- }
282
- }
283
- }
284
- exports.PxpApp = PxpApp;
1
+ "use strict";
2
+ /**
3
+ * Kplian Ltda 2020
4
+ *
5
+ * MIT
6
+ *
7
+ * Main pxp-nd file.
8
+ *
9
+ * @summary Handles all requests for pxp-ui or pxp-nd.
10
+ * @author Jaime Rivera
11
+ *
12
+ * Created at : 2020-06-13 18:09:48
13
+ * Last modified : 2020-09-20 18:24:45
14
+ */
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.PxpApp = void 0;
20
+ require("reflect-metadata");
21
+ const typeorm_1 = require("typeorm");
22
+ const express_fileupload_1 = __importDefault(require("express-fileupload"));
23
+ const express_1 = __importDefault(require("express"));
24
+ const passport_1 = __importDefault(require("passport"));
25
+ const express_session_1 = __importDefault(require("express-session"));
26
+ const typeorm_2 = require("typeorm");
27
+ const cors_1 = __importDefault(require("cors"));
28
+ const fs_1 = __importDefault(require("fs"));
29
+ const path_1 = __importDefault(require("path"));
30
+ const http_1 = __importDefault(require("http"));
31
+ /** swagger options **/
32
+ const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
33
+ const swagger_jsdoc_1 = __importDefault(require("swagger-jsdoc"));
34
+ const swaggerOptions_1 = __importDefault(require("./swaggerOptions"));
35
+ const loadControllers_1 = __importDefault(require("./lib/pxp/loadControllers"));
36
+ const pxp_1 = require("./lib/pxp");
37
+ // import { getAuthRoutes, customAuthRoutes } from '@pxp-nd/auth';
38
+ // import { configPassport } from '@pxp-nd/auth';
39
+ // import { Session } from '@pxp-nd/entities';
40
+ const typeorm_store_1 = require("typeorm-store");
41
+ const report_routes_1 = require("./lib/reports/report-routes");
42
+ const pxp_io_server_1 = __importDefault(require("./sockets/pxp-io-server"));
43
+ const modulesPxp = {
44
+ auth: '@pxp-nd/auth',
45
+ common: '@pxp-nd/common',
46
+ reports: '@pxp-nd/reports',
47
+ };
48
+ //auth configure
49
+ /**
50
+ *
51
+ * */
52
+ class PxpApp {
53
+ constructor(config) {
54
+ this.configAuth = null;
55
+ this.Report = null;
56
+ this.ReportGroup = null;
57
+ this.sockets = {};
58
+ this.config = {
59
+ defaultDbSettings: 'Orm',
60
+ apiPrefix: '/api',
61
+ logDuration: true,
62
+ middlewares: [],
63
+ };
64
+ this.getDurationInMilliseconds = (start) => {
65
+ const NS_PER_SEC = 1e9;
66
+ const NS_TO_MS = 1e6;
67
+ const diff = process.hrtime(start);
68
+ return (diff[0] * NS_PER_SEC + diff[1]) / NS_TO_MS;
69
+ };
70
+ this.folderModulesCreate();
71
+ this.config = Object.assign(Object.assign({}, this.config), config);
72
+ this.app = express_1.default();
73
+ this.controllers = [];
74
+ // this.initializeMiddlewares();
75
+ }
76
+ static get instance() {
77
+ return this._instance || (this._instance = new this(null));
78
+ }
79
+ set ConfigAuth(authOptions) {
80
+ this.configAuth = authOptions;
81
+ }
82
+ initializeSwagger() {
83
+ const options = {
84
+ customCss: '.swagger-ui .topbar { display: none }',
85
+ explorer: true,
86
+ };
87
+ const swaggerDocs = swagger_jsdoc_1.default(swaggerOptions_1.default);
88
+ this.app.use('/explorer', swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(swaggerDocs, options));
89
+ }
90
+ async loadControllers() {
91
+ // await this.connectToTheDatabase();
92
+ // await this.initializeAuthentication();
93
+ this.controllers = await loadControllers_1.default(this.config, this.io);
94
+ this.initializeRoutes();
95
+ this.initializeErrorHandling();
96
+ }
97
+ loadIOserver() {
98
+ this._httpServer = new http_1.default.Server(this.app);
99
+ if (this.config.enableSocket) {
100
+ this.io = new pxp_io_server_1.default(this._httpServer, this.sockets).io;
101
+ }
102
+ }
103
+ listen() {
104
+ this._httpServer.listen(process.env.PORT, () => {
105
+ console.log(`${'\x1b[36m'}App listening on the port ${process.env.PORT}${'\x1b[0m'}`);
106
+ });
107
+ }
108
+ getServer() {
109
+ return this.app;
110
+ }
111
+ initializeMiddlewares() {
112
+ this.app.use((req, res, next) => {
113
+ req.start = new Date();
114
+ if (this.config.logDuration) {
115
+ console.log(`${req.method} ${req.originalUrl} [STARTED]`);
116
+ const start = process.hrtime();
117
+ res.on('finish', () => {
118
+ const durationInMilliseconds = this.getDurationInMilliseconds(start);
119
+ console.log(`${req.method} ${req.originalUrl} [FINISHED] ${durationInMilliseconds.toLocaleString()} ms`);
120
+ });
121
+ res.on('close', () => {
122
+ const durationInMilliseconds = this.getDurationInMilliseconds(start);
123
+ console.log(`${req.method} ${req.originalUrl} [CLOSED] ${durationInMilliseconds.toLocaleString()} ms`);
124
+ });
125
+ }
126
+ next();
127
+ });
128
+ this.app.use(express_1.default.json());
129
+ this.app.use(express_1.default.urlencoded({ extended: false }));
130
+ this.app.use(express_fileupload_1.default({
131
+ limits: { fileSize: 5 * 1024 * 1024 },
132
+ }));
133
+ this.configCors();
134
+ }
135
+ async initializeAuthentication(configAuth) {
136
+ if (configAuth) {
137
+ const { configPassport, getAuthRoutes, customAuthRoutes } = configAuth();
138
+ this.initializeSession();
139
+ await this.initializePassport(configPassport, getAuthRoutes, customAuthRoutes);
140
+ }
141
+ else {
142
+ throw new Error(`Invalid config Auth, set ConfigAuth:\n
143
+ \t// App.ts file
144
+ \timport { configAuth } from '@pxp-nd/auth';
145
+ \t// In constructror set...
146
+ \tthis.ConfigAuth = configAuth;
147
+ \t//...`);
148
+ }
149
+ }
150
+ initializeErrorHandling() {
151
+ this.app.use(pxp_1.errorMiddleware);
152
+ }
153
+ async initializePassport(configPassport, getAuthRoutes, customAuthRoutes) {
154
+ configPassport(this.config.auth);
155
+ this.app.use(passport_1.default.initialize());
156
+ // @todo only validate session if authorization is not set(10/03/2021)
157
+ this.app.use(passport_1.default.session());
158
+ this.app.use((req, res, next) => {
159
+ if (req.headers.authorization) {
160
+ passport_1.default.authenticate('jwt', { session: false }, function (err, user, info) {
161
+ if (user) {
162
+ req.logIn(user, function (err) {
163
+ next();
164
+ });
165
+ }
166
+ else {
167
+ next();
168
+ }
169
+ })(req, res, next);
170
+ }
171
+ else {
172
+ next();
173
+ }
174
+ });
175
+ this.app.use((req, res, next) => {
176
+ next();
177
+ });
178
+ const routes = await customAuthRoutes();
179
+ routes.forEach((route) => this.app.use(route.router));
180
+ const authRoutes = getAuthRoutes(this.config.apiPrefix);
181
+ this.showRoutes(authRoutes);
182
+ this.app.use(authRoutes);
183
+ if (this.config.reports) {
184
+ if (!this.Report && !this.ReportGroup) {
185
+ throw new Error(`Invalid Report configuration, set Report and ReportGroup entities:\n
186
+ \t// App.ts file
187
+ \timport { Report, ReportGroup } from '@pxp-nd/common';
188
+ \t//...
189
+ \tthis.Report = Report;
190
+ \tthis.ReportGroup = ReportGroup;
191
+ `);
192
+ }
193
+ const reportRouter = report_routes_1.getReportsRouter(this.config, this.Report, this.ReportGroup);
194
+ this.showRoutes(reportRouter);
195
+ this.app.use(reportRouter);
196
+ }
197
+ }
198
+ configCors() {
199
+ const whitelist = process.env.WHITE_LIST ? String(process.env.WHITE_LIST).split(',') : [];
200
+ const corsOptions = {
201
+ credentials: true,
202
+ origin: function (origin, callback) {
203
+ if (whitelist.indexOf(origin) !== -1 || !origin) {
204
+ callback(null, true);
205
+ }
206
+ else {
207
+ callback(new Error('Not allowed by CORS'));
208
+ }
209
+ }
210
+ };
211
+ this.app.use(cors_1.default(corsOptions));
212
+ this.app.options('*', cors_1.default());
213
+ }
214
+ initializeSession() {
215
+ const repository = typeorm_2.getConnection().getRepository(this.config.session);
216
+ this.app.use(express_session_1.default({
217
+ secret: String(process.env.SECRET),
218
+ resave: false,
219
+ saveUninitialized: true,
220
+ store: new typeorm_store_1.TypeormStore({ repository }),
221
+ cookie: {
222
+ maxAge: 1000 * 60 * 60 * 168
223
+ // 24 = 1 day <=> 168 = 7 days
224
+ // Equals 1 day (1 day * 24 hr/1 day * 60 min/1 hr * 60 sec/1 min * 1000 ms / 1 sec)
225
+ }
226
+ }));
227
+ }
228
+ initializeRoutes() {
229
+ this.controllers.forEach((controller) => {
230
+ this.app.use(controller.router);
231
+ this.showRoutes(controller.router);
232
+ });
233
+ this.app.all('*', function (req, res) {
234
+ res.status(404).json({
235
+ error: {
236
+ code: 404,
237
+ message: 'Route not found'
238
+ }
239
+ });
240
+ });
241
+ }
242
+ // Show routes with config.showRoutes is true
243
+ showRoutes(router) {
244
+ const routes = router.stack.filter((r) => r.route)
245
+ .map((r) => {
246
+ return {
247
+ method: Object.keys(r.route.methods)[0].toUpperCase(),
248
+ path: r.route.path
249
+ };
250
+ });
251
+ if (this.config.showRoutes) {
252
+ routes.forEach((route) => console.log(`${'\x1b[31m'}${route.method.toUpperCase()}:\t${'\x1b[32m'}${route.path}${'\x1b[0m'}`));
253
+ console.log('');
254
+ }
255
+ }
256
+ async connectDatabase() {
257
+ await typeorm_1.createConnections();
258
+ }
259
+ async run() {
260
+ this.initializeSwagger();
261
+ this.initializeMiddlewares();
262
+ await this.connectDatabase();
263
+ // configure auth options
264
+ if (this.config.auth) {
265
+ await this.initializeAuthentication(this.configAuth);
266
+ }
267
+ // load ioServer
268
+ this.loadIOserver();
269
+ // load controllers and routes
270
+ await this.loadControllers();
271
+ }
272
+ folderModulesCreate() {
273
+ const dirModules = path_1.default.join(process.cwd(), 'dist/modules');
274
+ const dirModulesSrc = path_1.default.join(process.cwd(), 'src/modules');
275
+ if (!fs_1.default.existsSync(dirModules)) {
276
+ fs_1.default.mkdirSync(dirModules, '0744');
277
+ }
278
+ if (!fs_1.default.existsSync(dirModulesSrc)) {
279
+ fs_1.default.mkdirSync(dirModulesSrc, '0744');
280
+ }
281
+ }
282
+ }
283
+ exports.PxpApp = PxpApp;
@@ -1 +1 @@
1
- import 'reflect-metadata';
1
+ import 'reflect-metadata';