@manojkmfsi/monodog 1.0.25 → 1.1.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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/dist/config/swagger-config.js +345 -0
- package/dist/constants/index.js +26 -0
- package/dist/constants/middleware.js +71 -0
- package/dist/constants/port.js +20 -0
- package/dist/constants/security.js +67 -0
- package/dist/middleware/dashboard-startup.js +15 -18
- package/dist/middleware/security.js +10 -9
- package/dist/middleware/server-startup.js +12 -11
- package/dist/middleware/swagger-middleware.js +54 -0
- package/dist/routes/health-routes.js +1 -1
- package/dist/routes/package-routes.js +1 -1
- package/dist/services/health-service.js +84 -64
- package/dist/services/package-service.js +23 -1
- package/monodog-dashboard/dist/assets/{index-746f6c13.js → index-45e19f29.js} +1 -1
- package/monodog-dashboard/dist/index.html +1 -1
- package/package.json +5 -2
- package/src/config/swagger-config.ts +344 -0
- package/src/constants/index.ts +13 -0
- package/src/constants/middleware.ts +83 -0
- package/src/constants/port.ts +20 -0
- package/src/constants/security.ts +78 -0
- package/src/middleware/dashboard-startup.ts +30 -18
- package/src/middleware/security.ts +18 -9
- package/src/middleware/server-startup.ts +22 -11
- package/src/middleware/swagger-middleware.ts +57 -0
- package/src/routes/health-routes.ts +1 -1
- package/src/routes/package-routes.ts +1 -1
- package/src/services/health-service.ts +103 -79
- package/src/services/package-service.ts +27 -1
- package/src/types/swagger-jsdoc.d.ts +15 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>MonoDog Dashboard</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-45e19f29.js"></script>
|
|
8
8
|
<link rel="stylesheet" href="/assets/index-504dc418.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body class="bg-gray-100 text-gray-900">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@manojkmfsi/monodog",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "App for monodog monorepo",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"helmet": "^7.1.0",
|
|
15
15
|
"init": "^0.1.2",
|
|
16
16
|
"js-yaml": "^4.1.0",
|
|
17
|
-
"prisma": "^5.22.0"
|
|
17
|
+
"prisma": "^5.22.0",
|
|
18
|
+
"swagger-jsdoc": "^6.2.8",
|
|
19
|
+
"swagger-ui-express": "^5.0.1"
|
|
18
20
|
},
|
|
19
21
|
"devDependencies": {
|
|
20
22
|
"@types/body-parser": "^1.19.6",
|
|
@@ -24,6 +26,7 @@
|
|
|
24
26
|
"@types/js-yaml": "^4.0.9",
|
|
25
27
|
"@types/morgan": "^1.9.10",
|
|
26
28
|
"@types/node": "^20.19.27",
|
|
29
|
+
"@types/swagger-ui-express": "^4.1.6",
|
|
27
30
|
"cross-env": "^10.1.0",
|
|
28
31
|
"jest": "^29.7.0",
|
|
29
32
|
"jest-environment-jsdom": "^30.2.0",
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swagger API Documentation Configuration
|
|
3
|
+
* Defines OpenAPI specification for MonoDog API
|
|
4
|
+
*/
|
|
5
|
+
import { appConfig } from "../config-loader";
|
|
6
|
+
export const swaggerDefinition = {
|
|
7
|
+
openapi: '3.0.0',
|
|
8
|
+
info: {
|
|
9
|
+
title: 'MonoDog API',
|
|
10
|
+
version: '1.0.0',
|
|
11
|
+
description: 'Monorepo Analytics and Health Dashboard API',
|
|
12
|
+
contact: {
|
|
13
|
+
name: 'MonoDog Team',
|
|
14
|
+
url: 'https://github.com/mindfiredigital/monodog',
|
|
15
|
+
},
|
|
16
|
+
license: {
|
|
17
|
+
name: 'MIT',
|
|
18
|
+
url: 'https://opensource.org/licenses/MIT',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
servers: [
|
|
22
|
+
{
|
|
23
|
+
url: `http://${appConfig.server.host}:${appConfig.server.port}/api`,
|
|
24
|
+
description: 'Development server',
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
],
|
|
28
|
+
paths: {
|
|
29
|
+
'/packages': {
|
|
30
|
+
get: {
|
|
31
|
+
tags: ['Packages'],
|
|
32
|
+
summary: 'Get all packages',
|
|
33
|
+
operationId: 'getPackages',
|
|
34
|
+
responses: {
|
|
35
|
+
'200': {
|
|
36
|
+
description: 'List of packages',
|
|
37
|
+
content: {
|
|
38
|
+
'application/json': {
|
|
39
|
+
schema: { type: 'array', items: { $ref: '#/components/schemas/Package' } },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
'500': { description: 'Internal server error' },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
'/packages/{name}': {
|
|
48
|
+
get: {
|
|
49
|
+
tags: ['Packages'],
|
|
50
|
+
summary: 'Get package by name',
|
|
51
|
+
operationId: 'getPackageByName',
|
|
52
|
+
parameters: [{ name: 'name', in: 'path', required: true, schema: { type: 'string' } }],
|
|
53
|
+
responses: {
|
|
54
|
+
'200': {
|
|
55
|
+
description: 'Package details',
|
|
56
|
+
content: {
|
|
57
|
+
'application/json': {
|
|
58
|
+
schema: { $ref: '#/components/schemas/Package' },
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
'404': { description: 'Package not found' },
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
'/packages/refresh': {
|
|
67
|
+
post: {
|
|
68
|
+
tags: ['Packages'],
|
|
69
|
+
summary: 'Refresh packages',
|
|
70
|
+
operationId: 'refreshPackages',
|
|
71
|
+
responses: {
|
|
72
|
+
'200': { description: 'Packages refreshed successfully' },
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
'/packages/update-config': {
|
|
77
|
+
put: {
|
|
78
|
+
tags: ['Packages'],
|
|
79
|
+
summary: 'Update package configuration',
|
|
80
|
+
operationId: 'updatePackageConfig',
|
|
81
|
+
requestBody: {
|
|
82
|
+
required: true,
|
|
83
|
+
content: {
|
|
84
|
+
'application/json': {
|
|
85
|
+
schema: { $ref: '#/components/schemas/Package' },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
responses: {
|
|
90
|
+
'200': { description: 'Package configuration updated successfully' },
|
|
91
|
+
'400': { description: 'Invalid request' },
|
|
92
|
+
'404': { description: 'Package not found' },
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
'/health/packages': {
|
|
97
|
+
get: {
|
|
98
|
+
tags: ['Health'],
|
|
99
|
+
summary: 'Get packages health status',
|
|
100
|
+
operationId: 'getPackagesHealth',
|
|
101
|
+
responses: {
|
|
102
|
+
'200': {
|
|
103
|
+
description: 'Health status of all packages',
|
|
104
|
+
content: {
|
|
105
|
+
'application/json': {
|
|
106
|
+
schema: { type: 'array', items: { $ref: '#/components/schemas/PackageHealth' } },
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
'/health/refresh': {
|
|
114
|
+
post: {
|
|
115
|
+
tags: ['Health'],
|
|
116
|
+
summary: 'Refresh health status',
|
|
117
|
+
operationId: 'refreshHealth',
|
|
118
|
+
responses: {
|
|
119
|
+
'200': { description: 'Health status refreshed successfully' },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
'/commits/{packagePath}': {
|
|
124
|
+
get: {
|
|
125
|
+
tags: ['Commits'],
|
|
126
|
+
summary: 'Get commits for a package',
|
|
127
|
+
operationId: 'getCommits',
|
|
128
|
+
parameters: [{ name: 'packagePath', in: 'path', required: true, schema: { type: 'string' } }],
|
|
129
|
+
responses: {
|
|
130
|
+
'200': {
|
|
131
|
+
description: 'List of commits',
|
|
132
|
+
content: {
|
|
133
|
+
'application/json': {
|
|
134
|
+
schema: { type: 'array', items: { $ref: '#/components/schemas/Commit' } },
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
'/config/files': {
|
|
142
|
+
get: {
|
|
143
|
+
tags: ['Configuration'],
|
|
144
|
+
summary: 'Get configuration files',
|
|
145
|
+
operationId: 'getConfigFiles',
|
|
146
|
+
responses: {
|
|
147
|
+
'200': {
|
|
148
|
+
description: 'List of configuration files',
|
|
149
|
+
content: {
|
|
150
|
+
'application/json': {
|
|
151
|
+
schema: { type: 'array', items: { $ref: '#/components/schemas/ConfigFile' } },
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
'/config/files/{id}': {
|
|
159
|
+
put: {
|
|
160
|
+
tags: ['Configuration'],
|
|
161
|
+
summary: 'Update configuration file',
|
|
162
|
+
operationId: 'updateConfigFile',
|
|
163
|
+
parameters: [{ name: 'id', in: 'path', required: true, schema: { type: 'string' } }],
|
|
164
|
+
requestBody: {
|
|
165
|
+
required: true,
|
|
166
|
+
content: {
|
|
167
|
+
'application/json': {
|
|
168
|
+
schema: { $ref: '#/components/schemas/ConfigFile' },
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
responses: {
|
|
173
|
+
'200': { description: 'Configuration file updated successfully' },
|
|
174
|
+
'400': { description: 'Invalid request' },
|
|
175
|
+
'404': { description: 'Configuration file not found' },
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
tags: [
|
|
181
|
+
{
|
|
182
|
+
name: 'Packages',
|
|
183
|
+
description: 'Package management and analysis endpoints',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: 'Health',
|
|
187
|
+
description: 'Health monitoring and status endpoints',
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: 'Commits',
|
|
191
|
+
description: 'Git commit history and analysis endpoints',
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: 'Configuration',
|
|
195
|
+
description: 'Configuration file management endpoints',
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
components: {
|
|
199
|
+
schemas: {
|
|
200
|
+
Package: {
|
|
201
|
+
type: 'object',
|
|
202
|
+
properties: {
|
|
203
|
+
name: {
|
|
204
|
+
type: 'string',
|
|
205
|
+
description: 'Package name',
|
|
206
|
+
},
|
|
207
|
+
path: {
|
|
208
|
+
type: 'string',
|
|
209
|
+
description: 'Package path in monorepo',
|
|
210
|
+
},
|
|
211
|
+
version: {
|
|
212
|
+
type: 'string',
|
|
213
|
+
description: 'Package version',
|
|
214
|
+
},
|
|
215
|
+
size: {
|
|
216
|
+
type: 'number',
|
|
217
|
+
description: 'Package size in bytes',
|
|
218
|
+
},
|
|
219
|
+
dependencies: {
|
|
220
|
+
type: 'array',
|
|
221
|
+
items: {
|
|
222
|
+
type: 'string',
|
|
223
|
+
},
|
|
224
|
+
description: 'List of package dependencies',
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
PackageHealth: {
|
|
229
|
+
type: 'object',
|
|
230
|
+
properties: {
|
|
231
|
+
packageName: {
|
|
232
|
+
type: 'string',
|
|
233
|
+
description: 'Name of the package',
|
|
234
|
+
},
|
|
235
|
+
healthScore: {
|
|
236
|
+
type: 'number',
|
|
237
|
+
description: 'Health score (0-100)',
|
|
238
|
+
minimum: 0,
|
|
239
|
+
maximum: 100,
|
|
240
|
+
},
|
|
241
|
+
lintStatus: {
|
|
242
|
+
type: 'string',
|
|
243
|
+
enum: ['pass', 'warning', 'fail'],
|
|
244
|
+
description: 'Linting status',
|
|
245
|
+
},
|
|
246
|
+
buildStatus: {
|
|
247
|
+
type: 'string',
|
|
248
|
+
enum: ['success', 'failed', 'pending'],
|
|
249
|
+
description: 'Build status',
|
|
250
|
+
},
|
|
251
|
+
securityStatus: {
|
|
252
|
+
type: 'string',
|
|
253
|
+
enum: ['secure', 'warning', 'vulnerable'],
|
|
254
|
+
description: 'Security status',
|
|
255
|
+
},
|
|
256
|
+
testCoverage: {
|
|
257
|
+
type: 'number',
|
|
258
|
+
description: 'Test coverage percentage',
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
Commit: {
|
|
263
|
+
type: 'object',
|
|
264
|
+
properties: {
|
|
265
|
+
hash: {
|
|
266
|
+
type: 'string',
|
|
267
|
+
description: 'Commit hash',
|
|
268
|
+
},
|
|
269
|
+
author: {
|
|
270
|
+
type: 'string',
|
|
271
|
+
description: 'Commit author',
|
|
272
|
+
},
|
|
273
|
+
message: {
|
|
274
|
+
type: 'string',
|
|
275
|
+
description: 'Commit message',
|
|
276
|
+
},
|
|
277
|
+
date: {
|
|
278
|
+
type: 'string',
|
|
279
|
+
format: 'date-time',
|
|
280
|
+
description: 'Commit date',
|
|
281
|
+
},
|
|
282
|
+
filesChanged: {
|
|
283
|
+
type: 'number',
|
|
284
|
+
description: 'Number of files changed',
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
ConfigFile: {
|
|
289
|
+
type: 'object',
|
|
290
|
+
properties: {
|
|
291
|
+
id: {
|
|
292
|
+
type: 'string',
|
|
293
|
+
description: 'Configuration file ID',
|
|
294
|
+
},
|
|
295
|
+
name: {
|
|
296
|
+
type: 'string',
|
|
297
|
+
description: 'Configuration file name',
|
|
298
|
+
},
|
|
299
|
+
path: {
|
|
300
|
+
type: 'string',
|
|
301
|
+
description: 'Configuration file path',
|
|
302
|
+
},
|
|
303
|
+
content: {
|
|
304
|
+
type: 'string',
|
|
305
|
+
description: 'Configuration file content',
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
Error: {
|
|
310
|
+
type: 'object',
|
|
311
|
+
properties: {
|
|
312
|
+
error: {
|
|
313
|
+
type: 'string',
|
|
314
|
+
description: 'Error message',
|
|
315
|
+
},
|
|
316
|
+
message: {
|
|
317
|
+
type: 'string',
|
|
318
|
+
description: 'Detailed error message',
|
|
319
|
+
},
|
|
320
|
+
code: {
|
|
321
|
+
type: 'string',
|
|
322
|
+
description: 'Error code',
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
responses: {
|
|
328
|
+
UnauthorizedError: {
|
|
329
|
+
description: 'Unauthorized access',
|
|
330
|
+
},
|
|
331
|
+
NotFoundError: {
|
|
332
|
+
description: 'Resource not found',
|
|
333
|
+
},
|
|
334
|
+
InternalServerError: {
|
|
335
|
+
description: 'Internal server error',
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export const swaggerOptions = {
|
|
342
|
+
definition: swaggerDefinition,
|
|
343
|
+
apis: [], // Using only definition, no JSDoc file scanning
|
|
344
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Middleware Constants
|
|
3
|
+
* Defines constants used across middleware modules
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HTTP status code for internal server error
|
|
8
|
+
*/
|
|
9
|
+
export const HTTP_STATUS_INTERNAL_SERVER_ERROR = 500;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* HTTP status code for not found
|
|
13
|
+
*/
|
|
14
|
+
export const HTTP_STATUS_NOT_FOUND = 404;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* HTTP status code for bad request
|
|
18
|
+
*/
|
|
19
|
+
export const HTTP_STATUS_BAD_REQUEST = 400;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Error message for port already in use
|
|
23
|
+
*/
|
|
24
|
+
export const ERROR_PORT_IN_USE = (port: number): string =>
|
|
25
|
+
`Port ${port} is already in use. Please specify a different port.`;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Error message for permission denied
|
|
29
|
+
*/
|
|
30
|
+
export const ERROR_PERMISSION_DENIED = (port: number): string =>
|
|
31
|
+
`Permission denied to listen on port ${port}. Use a port above 1024.`;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Error message for internal server error
|
|
35
|
+
*/
|
|
36
|
+
export const ERROR_INTERNAL_SERVER = 'Internal server error';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Success message for server start
|
|
40
|
+
*/
|
|
41
|
+
export const SUCCESS_SERVER_START = (host: string, port: number): string =>
|
|
42
|
+
`Backend server listening on http://${host}:${port}`;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Success message for dashboard start
|
|
46
|
+
*/
|
|
47
|
+
export const SUCCESS_DASHBOARD_START = (host: string, port: number): string =>
|
|
48
|
+
`Dashboard listening on http://${host}:${port}`;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Message for graceful shutdown
|
|
52
|
+
*/
|
|
53
|
+
export const MESSAGE_GRACEFUL_SHUTDOWN = 'SIGTERM signal received: closing HTTP server';
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Message for server closed
|
|
57
|
+
*/
|
|
58
|
+
export const MESSAGE_SERVER_CLOSED = 'HTTP server closed';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Message for dashboard graceful shutdown
|
|
62
|
+
*/
|
|
63
|
+
export const MESSAGE_DASHBOARD_GRACEFUL_SHUTDOWN = 'SIGTERM signal received: closing dashboard server';
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Message for dashboard closed
|
|
67
|
+
*/
|
|
68
|
+
export const MESSAGE_DASHBOARD_CLOSED = 'Dashboard server closed';
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Content-Type header for JavaScript
|
|
72
|
+
*/
|
|
73
|
+
export const CONTENT_TYPE_JAVASCRIPT = 'application/javascript';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Error serving index.html message
|
|
77
|
+
*/
|
|
78
|
+
export const ERROR_SERVING_INDEX_HTML = 'Error serving index.html:';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Shutdown instruction message
|
|
82
|
+
*/
|
|
83
|
+
export const MESSAGE_SHUTDOWN_INSTRUCTION = 'Press Ctrl+C to quit.';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port Constants
|
|
3
|
+
* Defines valid port range and port-related configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Minimum valid port number (above system reserved ports)
|
|
8
|
+
*/
|
|
9
|
+
export const PORT_MIN = 1024;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Maximum valid port number
|
|
13
|
+
*/
|
|
14
|
+
export const PORT_MAX = 65535;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Port validation error message
|
|
18
|
+
*/
|
|
19
|
+
export const PORT_VALIDATION_ERROR_MESSAGE = (min: number, max: number): string =>
|
|
20
|
+
`Port must be between ${min} and ${max}`;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Constants
|
|
3
|
+
* Defines security-related configuration and constants
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Request timeout duration in milliseconds (30 seconds)
|
|
8
|
+
*/
|
|
9
|
+
export const REQUEST_TIMEOUT = 30000;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Response timeout duration in milliseconds (30 seconds)
|
|
13
|
+
*/
|
|
14
|
+
export const RESPONSE_TIMEOUT = 30000;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* CORS methods allowed for API
|
|
18
|
+
*/
|
|
19
|
+
export const CORS_API_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'] as const;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* CORS headers allowed
|
|
23
|
+
*/
|
|
24
|
+
export const CORS_ALLOWED_HEADERS = ['Content-Type', 'Authorization'] as const;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Body parser JSON size limit
|
|
28
|
+
*/
|
|
29
|
+
export const BODY_PARSER_LIMIT = '1mb';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Cache control header for no-cache responses
|
|
33
|
+
*/
|
|
34
|
+
export const CACHE_CONTROL_NO_CACHE = 'private, no-cache, no-store, must-revalidate';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Cache control header for static assets
|
|
38
|
+
*/
|
|
39
|
+
export const CACHE_CONTROL_STATIC = '1d';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Default localhost hostname
|
|
43
|
+
*/
|
|
44
|
+
export const DEFAULT_LOCALHOST = 'localhost';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Wildcard address for listening on all interfaces
|
|
48
|
+
*/
|
|
49
|
+
export const WILDCARD_ADDRESS = '0.0.0.0';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* HTTP protocol prefix
|
|
53
|
+
*/
|
|
54
|
+
export const HTTP_PROTOCOL = 'http://';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* CSP directives for Helmet
|
|
58
|
+
*/
|
|
59
|
+
export const CSP_DIRECTIVES = {
|
|
60
|
+
defaultSrc: ["'self'"],
|
|
61
|
+
scriptSrc: ["'self'"],
|
|
62
|
+
imgSrc: ["'self'", 'data:', 'https:'],
|
|
63
|
+
} as const;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Static file extensions pattern
|
|
67
|
+
*/
|
|
68
|
+
export const STATIC_FILE_PATTERN = /(.ico|.js|.css|.jpg|.png|.map|.woff|.woff2|.ttf)$/i;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Expires header for no-cache responses
|
|
72
|
+
*/
|
|
73
|
+
export const EXPIRES_HEADER = '-1';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Pragma header for no-cache responses
|
|
77
|
+
*/
|
|
78
|
+
export const PRAGMA_HEADER = 'no-cache';
|
|
@@ -17,10 +17,23 @@ import {
|
|
|
17
17
|
createTimeoutMiddleware,
|
|
18
18
|
buildApiUrl,
|
|
19
19
|
} from './security';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
import {
|
|
21
|
+
PORT_MIN,
|
|
22
|
+
PORT_MAX,
|
|
23
|
+
PORT_VALIDATION_ERROR_MESSAGE,
|
|
24
|
+
CACHE_CONTROL_NO_CACHE,
|
|
25
|
+
EXPIRES_HEADER,
|
|
26
|
+
PRAGMA_HEADER,
|
|
27
|
+
STATIC_FILE_PATTERN,
|
|
28
|
+
CONTENT_TYPE_JAVASCRIPT,
|
|
29
|
+
ERROR_SERVING_INDEX_HTML,
|
|
30
|
+
MESSAGE_GRACEFUL_SHUTDOWN,
|
|
31
|
+
MESSAGE_DASHBOARD_GRACEFUL_SHUTDOWN,
|
|
32
|
+
MESSAGE_DASHBOARD_CLOSED,
|
|
33
|
+
SUCCESS_DASHBOARD_START,
|
|
34
|
+
ERROR_PORT_IN_USE,
|
|
35
|
+
ERROR_PERMISSION_DENIED,
|
|
36
|
+
} from '../constants';
|
|
24
37
|
|
|
25
38
|
/**
|
|
26
39
|
* Validate port number
|
|
@@ -29,7 +42,7 @@ function validatePort(port: string | number): number {
|
|
|
29
42
|
const portNum = typeof port === 'string' ? parseInt(port, 10) : port;
|
|
30
43
|
|
|
31
44
|
if (isNaN(portNum) || portNum < PORT_MIN || portNum > PORT_MAX) {
|
|
32
|
-
throw new Error(
|
|
45
|
+
throw new Error(PORT_VALIDATION_ERROR_MESSAGE(PORT_MIN, PORT_MAX));
|
|
33
46
|
}
|
|
34
47
|
|
|
35
48
|
return portNum;
|
|
@@ -55,8 +68,8 @@ function createDashboardApp(): Express {
|
|
|
55
68
|
|
|
56
69
|
// Environment config endpoint
|
|
57
70
|
app.get('/env-config.js', (_req, res) => {
|
|
58
|
-
res.setHeader('Content-Type',
|
|
59
|
-
res.setHeader('Cache-Control',
|
|
71
|
+
res.setHeader('Content-Type', CONTENT_TYPE_JAVASCRIPT);
|
|
72
|
+
res.setHeader('Cache-Control', CACHE_CONTROL_NO_CACHE);
|
|
60
73
|
|
|
61
74
|
res.send(
|
|
62
75
|
`window.ENV = { API_URL: "${apiUrl}" };`
|
|
@@ -65,24 +78,23 @@ function createDashboardApp(): Express {
|
|
|
65
78
|
|
|
66
79
|
// Request logging
|
|
67
80
|
app.use(httpLogger);
|
|
68
|
-
// app.use(requestLogger);
|
|
69
81
|
|
|
70
82
|
// SPA routing: serve index.html for non-static routes
|
|
71
83
|
app.use((_req, _res, next) => {
|
|
72
|
-
if (
|
|
84
|
+
if (STATIC_FILE_PATTERN.test(_req.path)) {
|
|
73
85
|
next();
|
|
74
86
|
} else {
|
|
75
87
|
_res.header(
|
|
76
88
|
'Cache-Control',
|
|
77
|
-
|
|
89
|
+
CACHE_CONTROL_NO_CACHE
|
|
78
90
|
);
|
|
79
|
-
_res.header('Expires',
|
|
80
|
-
_res.header('Pragma',
|
|
91
|
+
_res.header('Expires', EXPIRES_HEADER);
|
|
92
|
+
_res.header('Pragma', PRAGMA_HEADER);
|
|
81
93
|
_res.sendFile('index.html', {
|
|
82
94
|
root: path.resolve(__dirname, '..', '..', 'monodog-dashboard', 'dist'),
|
|
83
95
|
}, (err: Error | null) => {
|
|
84
96
|
if (err) {
|
|
85
|
-
AppLogger.error(
|
|
97
|
+
AppLogger.error(ERROR_SERVING_INDEX_HTML, err);
|
|
86
98
|
_res.status(500).json({ error: 'Internal server error' });
|
|
87
99
|
}
|
|
88
100
|
});
|
|
@@ -116,16 +128,16 @@ export function serveDashboard(rootPath: string): void {
|
|
|
116
128
|
const app = createDashboardApp();
|
|
117
129
|
|
|
118
130
|
const server = app.listen(validatedPort, host, () => {
|
|
119
|
-
console.log(
|
|
131
|
+
console.log(SUCCESS_DASHBOARD_START(host, validatedPort));
|
|
120
132
|
console.log('Press Ctrl+C to quit.');
|
|
121
133
|
});
|
|
122
134
|
|
|
123
135
|
server.on('error', (err: NodeJS.ErrnoException) => {
|
|
124
136
|
if (err.code === 'EADDRINUSE') {
|
|
125
|
-
AppLogger.error(
|
|
137
|
+
AppLogger.error(ERROR_PORT_IN_USE(validatedPort), err);
|
|
126
138
|
process.exit(1);
|
|
127
139
|
} else if (err.code === 'EACCES') {
|
|
128
|
-
AppLogger.error(
|
|
140
|
+
AppLogger.error(ERROR_PERMISSION_DENIED(validatedPort), err);
|
|
129
141
|
process.exit(1);
|
|
130
142
|
} else {
|
|
131
143
|
AppLogger.error('Server failed to start:', err);
|
|
@@ -135,9 +147,9 @@ export function serveDashboard(rootPath: string): void {
|
|
|
135
147
|
|
|
136
148
|
// Graceful shutdown
|
|
137
149
|
process.on('SIGTERM', () => {
|
|
138
|
-
AppLogger.info(
|
|
150
|
+
AppLogger.info(MESSAGE_DASHBOARD_GRACEFUL_SHUTDOWN);
|
|
139
151
|
server.close(() => {
|
|
140
|
-
AppLogger.info(
|
|
152
|
+
AppLogger.info(MESSAGE_DASHBOARD_CLOSED);
|
|
141
153
|
process.exit(0);
|
|
142
154
|
});
|
|
143
155
|
});
|