@platformatic/runtime 2.72.0 → 3.0.0-alpha.1

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/lib/errors.js CHANGED
@@ -4,113 +4,155 @@ const createError = require('@fastify/error')
4
4
 
5
5
  const ERROR_PREFIX = 'PLT_RUNTIME'
6
6
 
7
- module.exports = {
8
- AddressInUseError: createError(`${ERROR_PREFIX}_EADDR_IN_USE`, 'The current port is in use by another application'),
9
- RuntimeExitedError: createError(`${ERROR_PREFIX}_RUNTIME_EXIT`, 'The runtime exited before the operation completed'),
10
- RuntimeAbortedError: createError(`${ERROR_PREFIX}_RUNTIME_ABORT`, 'The runtime aborted the operation'),
11
- // The following two use the same code as we only need to differentiate the label
12
- ServiceExitedError: createError(
13
- `${ERROR_PREFIX}_SERVICE_EXIT`,
14
- 'The service "%s" exited prematurely with error code %d'
15
- ),
16
- WorkerExitedError: createError(
17
- `${ERROR_PREFIX}_SERVICE_EXIT`,
18
- 'The worker %s of the service "%s" exited prematurely with error code %d'
19
- ),
20
- UnknownRuntimeAPICommandError: createError(
21
- `${ERROR_PREFIX}_UNKNOWN_RUNTIME_API_COMMAND`,
22
- 'Unknown Runtime API command "%s"'
23
- ),
24
- ServiceNotFoundError: createError(
25
- `${ERROR_PREFIX}_SERVICE_NOT_FOUND`,
26
- 'Service %s not found. Available services are: %s'
27
- ),
28
- WorkerNotFoundError: createError(
29
- `${ERROR_PREFIX}_WORKER_NOT_FOUND`,
30
- 'Worker %s of service %s not found. Available services are: %s'
31
- ),
32
- ServiceNotStartedError: createError(`${ERROR_PREFIX}_SERVICE_NOT_STARTED`, "Service with id '%s' is not started"),
33
- ServiceStartTimeoutError: createError(
34
- `${ERROR_PREFIX}_SERVICE_START_TIMEOUT`,
35
- "Service with id '%s' failed to start in %dms."
36
- ),
37
- FailedToRetrieveOpenAPISchemaError: createError(
38
- `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_OPENAPI_SCHEMA`,
39
- 'Failed to retrieve OpenAPI schema for service with id "%s": %s'
40
- ),
41
- FailedToRetrieveGraphQLSchemaError: createError(
42
- `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_GRAPHQL_SCHEMA`,
43
- 'Failed to retrieve GraphQL schema for service with id "%s": %s'
44
- ),
45
- FailedToRetrieveMetaError: createError(
46
- `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_META`,
47
- 'Failed to retrieve metadata for service with id "%s": %s'
48
- ),
49
- FailedToRetrieveMetricsError: createError(
50
- `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_METRICS`,
51
- 'Failed to retrieve metrics for service with id "%s": %s'
52
- ),
53
- FailedToRetrieveHealthError: createError(
54
- `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_HEALTH`,
55
- 'Failed to retrieve health for service with id "%s": %s'
56
- ),
57
- FailedToPerformCustomHealthCheckError: createError(
58
- `${ERROR_PREFIX}_FAILED_TO_PERFORM_CUSTOM_HEALTH_CHECK`,
59
- 'Failed to perform custom healthcheck for service with id "%s": %s'
60
- ),
61
- FailedToPerformCustomReadinessCheckError: createError(
62
- `${ERROR_PREFIX}_FAILED_TO_PERFORM_CUSTOM_READINESS_CHECK`,
63
- 'Failed to perform custom readiness check for service with id "%s": %s'
64
- ),
65
- ApplicationAlreadyStartedError: createError(
66
- `${ERROR_PREFIX}_APPLICATION_ALREADY_STARTED`,
67
- 'Application is already started'
68
- ),
69
- ApplicationNotStartedError: createError(
70
- `${ERROR_PREFIX}_APPLICATION_NOT_STARTED`,
71
- 'Application has not been started'
72
- ),
73
- ConfigPathMustBeStringError: createError(
74
- `${ERROR_PREFIX}_CONFIG_PATH_MUST_BE_STRING`,
75
- 'Config path must be a string'
76
- ),
77
- NoConfigFileFoundError: createError(`${ERROR_PREFIX}_NO_CONFIG_FILE_FOUND`, "No config file found for service '%s'"),
78
- InvalidEntrypointError: createError(`${ERROR_PREFIX}_INVALID_ENTRYPOINT`, "Invalid entrypoint: '%s' does not exist"),
79
- MissingEntrypointError: createError(`${ERROR_PREFIX}_MISSING_ENTRYPOINT`, 'Missing application entrypoint.'),
80
- InvalidServicesWithWebError: createError(
81
- `${ERROR_PREFIX}_INVALID_SERVICES_WITH_WEB`,
82
- 'The "services" property cannot be used when the "web" property is also defined'
83
- ),
84
- MissingDependencyError: createError(`${ERROR_PREFIX}_MISSING_DEPENDENCY`, 'Missing dependency: "%s"'),
85
- InspectAndInspectBrkError: createError(
86
- `${ERROR_PREFIX}_INSPECT_AND_INSPECT_BRK`,
87
- '--inspect and --inspect-brk cannot be used together'
88
- ),
89
- InspectorPortError: createError(
90
- `${ERROR_PREFIX}_INSPECTOR_PORT`,
91
- 'Inspector port must be 0 or in range 1024 to 65535'
92
- ),
93
- InspectorHostError: createError(`${ERROR_PREFIX}_INSPECTOR_HOST`, 'Inspector host cannot be empty'),
94
- CannotMapSpecifierToAbsolutePathError: createError(
95
- `${ERROR_PREFIX}_CANNOT_MAP_SPECIFIER_TO_ABSOLUTE_PATH`,
96
- 'Cannot map "%s" to an absolute path'
97
- ),
98
- NodeInspectorFlagsNotSupportedError: createError(
99
- `${ERROR_PREFIX}_NODE_INSPECTOR_FLAGS_NOT_SUPPORTED`,
100
- "The Node.js inspector flags are not supported. Please use 'platformatic start --inspect' instead."
101
- ),
102
- FailedToUnlinkManagementApiSocket: createError(
103
- `${ERROR_PREFIX}_FAILED_TO_UNLINK_MANAGEMENT_API_SOCKET`,
104
- 'Failed to unlink management API socket "%s"'
105
- ),
106
- LogFileNotFound: createError(`${ERROR_PREFIX}_LOG_FILE_NOT_FOUND`, 'Log file with index %s not found', 404),
107
- WorkerIsRequired: createError(`${ERROR_PREFIX}_REQUIRED_WORKER`, 'The worker parameter is required'),
108
- InvalidArgumentError: createError(`${ERROR_PREFIX}_INVALID_ARGUMENT`, 'Invalid argument: "%s"'),
109
- MessagingError: createError(`${ERROR_PREFIX}_MESSAGING_ERROR`, 'Cannot send a message to service "%s": %s'),
7
+ const AddressInUseError = createError(
8
+ `${ERROR_PREFIX}_EADDR_IN_USE`,
9
+ 'The current port is in use by another application'
10
+ )
11
+ const RuntimeExitedError = createError(
12
+ `${ERROR_PREFIX}_RUNTIME_EXIT`,
13
+ 'The runtime exited before the operation completed'
14
+ )
15
+ const RuntimeAbortedError = createError(`${ERROR_PREFIX}_RUNTIME_ABORT`, 'The runtime aborted the operation')
16
+ // The following two use the same code as we only need to differentiate the label
17
+ const ServiceExitedError = createError(
18
+ `${ERROR_PREFIX}_SERVICE_EXIT`,
19
+ 'The service "%s" exited prematurely with error code %d'
20
+ )
21
+ const WorkerExitedError = createError(
22
+ `${ERROR_PREFIX}_SERVICE_EXIT`,
23
+ 'The worker %s of the service "%s" exited prematurely with error code %d'
24
+ )
25
+ const UnknownRuntimeAPICommandError = createError(
26
+ `${ERROR_PREFIX}_UNKNOWN_RUNTIME_API_COMMAND`,
27
+ 'Unknown Runtime API command "%s"'
28
+ )
29
+ const ServiceNotFoundError = createError(
30
+ `${ERROR_PREFIX}_SERVICE_NOT_FOUND`,
31
+ 'Service %s not found. Available services are: %s'
32
+ )
33
+ const WorkerNotFoundError = createError(
34
+ `${ERROR_PREFIX}_WORKER_NOT_FOUND`,
35
+ 'Worker %s of service %s not found. Available services are: %s'
36
+ )
37
+ const ServiceNotStartedError = createError(`${ERROR_PREFIX}_SERVICE_NOT_STARTED`, "Service with id '%s' is not started")
38
+ const ServiceStartTimeoutError = createError(
39
+ `${ERROR_PREFIX}_SERVICE_START_TIMEOUT`,
40
+ "Service with id '%s' failed to start in %dms."
41
+ )
42
+ const FailedToRetrieveOpenAPISchemaError = createError(
43
+ `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_OPENAPI_SCHEMA`,
44
+ 'Failed to retrieve OpenAPI schema for service with id "%s": %s'
45
+ )
46
+ const FailedToRetrieveGraphQLSchemaError = createError(
47
+ `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_GRAPHQL_SCHEMA`,
48
+ 'Failed to retrieve GraphQL schema for service with id "%s": %s'
49
+ )
50
+ const FailedToRetrieveMetaError = createError(
51
+ `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_META`,
52
+ 'Failed to retrieve metadata for service with id "%s": %s'
53
+ )
54
+ const FailedToRetrieveMetricsError = createError(
55
+ `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_METRICS`,
56
+ 'Failed to retrieve metrics for service with id "%s": %s'
57
+ )
58
+ const FailedToRetrieveHealthError = createError(
59
+ `${ERROR_PREFIX}_FAILED_TO_RETRIEVE_HEALTH`,
60
+ 'Failed to retrieve health for service with id "%s": %s'
61
+ )
62
+ const FailedToPerformCustomHealthCheckError = createError(
63
+ `${ERROR_PREFIX}_FAILED_TO_PERFORM_CUSTOM_HEALTH_CHECK`,
64
+ 'Failed to perform custom healthcheck for service with id "%s": %s'
65
+ )
66
+ const FailedToPerformCustomReadinessCheckError = createError(
67
+ `${ERROR_PREFIX}_FAILED_TO_PERFORM_CUSTOM_READINESS_CHECK`,
68
+ 'Failed to perform custom readiness check for service with id "%s": %s'
69
+ )
70
+ const ApplicationAlreadyStartedError = createError(
71
+ `${ERROR_PREFIX}_APPLICATION_ALREADY_STARTED`,
72
+ 'Application is already started'
73
+ )
74
+ const ApplicationNotStartedError = createError(
75
+ `${ERROR_PREFIX}_APPLICATION_NOT_STARTED`,
76
+ 'Application has not been started'
77
+ )
78
+ const ConfigPathMustBeStringError = createError(
79
+ `${ERROR_PREFIX}_CONFIG_PATH_MUST_BE_STRING`,
80
+ 'Config path must be a string'
81
+ )
82
+ const NoConfigFileFoundError = createError(
83
+ `${ERROR_PREFIX}_NO_CONFIG_FILE_FOUND`,
84
+ "No config file found for service '%s'"
85
+ )
86
+ const InvalidEntrypointError = createError(
87
+ `${ERROR_PREFIX}_INVALID_ENTRYPOINT`,
88
+ "Invalid entrypoint: '%s' does not exist"
89
+ )
90
+ const MissingEntrypointError = createError(`${ERROR_PREFIX}_MISSING_ENTRYPOINT`, 'Missing application entrypoint.')
91
+ const InvalidServicesWithWebError = createError(
92
+ `${ERROR_PREFIX}_INVALID_SERVICES_WITH_WEB`,
93
+ 'The "services" property cannot be used when the "web" property is also defined'
94
+ )
95
+ const MissingDependencyError = createError(`${ERROR_PREFIX}_MISSING_DEPENDENCY`, 'Missing dependency: "%s"')
96
+ const InspectAndInspectBrkError = createError(
97
+ `${ERROR_PREFIX}_INSPECT_AND_INSPECT_BRK`,
98
+ '--inspect and --inspect-brk cannot be used together'
99
+ )
100
+ const InspectorPortError = createError(
101
+ `${ERROR_PREFIX}_INSPECTOR_PORT`,
102
+ 'Inspector port must be 0 or in range 1024 to 65535'
103
+ )
104
+ const InspectorHostError = createError(`${ERROR_PREFIX}_INSPECTOR_HOST`, 'Inspector host cannot be empty')
105
+ const CannotMapSpecifierToAbsolutePathError = createError(
106
+ `${ERROR_PREFIX}_CANNOT_MAP_SPECIFIER_TO_ABSOLUTE_PATH`,
107
+ 'Cannot map "%s" to an absolute path'
108
+ )
109
+ const NodeInspectorFlagsNotSupportedError = createError(
110
+ `${ERROR_PREFIX}_NODE_INSPECTOR_FLAGS_NOT_SUPPORTED`,
111
+ "The Node.js inspector flags are not supported. Please use 'platformatic start --inspect' instead."
112
+ )
113
+ const FailedToUnlinkManagementApiSocket = createError(
114
+ `${ERROR_PREFIX}_FAILED_TO_UNLINK_MANAGEMENT_API_SOCKET`,
115
+ 'Failed to unlink management API socket "%s"'
116
+ )
117
+ const LogFileNotFound = createError(`${ERROR_PREFIX}_LOG_FILE_NOT_FOUND`, 'Log file with index %s not found', 404)
118
+ const WorkerIsRequired = createError(`${ERROR_PREFIX}_REQUIRED_WORKER`, 'The worker parameter is required')
119
+ const InvalidArgumentError = createError(`${ERROR_PREFIX}_INVALID_ARGUMENT`, 'Invalid argument: "%s"')
120
+ const MessagingError = createError(`${ERROR_PREFIX}_MESSAGING_ERROR`, 'Cannot send a message to service "%s": %s')
110
121
 
111
- // TODO: should remove next one as it's not used anymore
112
- CannotRemoveServiceOnUpdateError: createError(
113
- `${ERROR_PREFIX}_CANNOT_REMOVE_SERVICE_ON_UPDATE`,
114
- 'Cannot remove service "%s" when updating a Runtime'
115
- )
122
+ module.exports = {
123
+ AddressInUseError,
124
+ RuntimeExitedError,
125
+ RuntimeAbortedError,
126
+ ServiceExitedError,
127
+ WorkerExitedError,
128
+ UnknownRuntimeAPICommandError,
129
+ ServiceNotFoundError,
130
+ WorkerNotFoundError,
131
+ ServiceNotStartedError,
132
+ ServiceStartTimeoutError,
133
+ FailedToRetrieveOpenAPISchemaError,
134
+ FailedToRetrieveGraphQLSchemaError,
135
+ FailedToRetrieveMetaError,
136
+ FailedToRetrieveMetricsError,
137
+ FailedToRetrieveHealthError,
138
+ FailedToPerformCustomHealthCheckError,
139
+ FailedToPerformCustomReadinessCheckError,
140
+ ApplicationAlreadyStartedError,
141
+ ApplicationNotStartedError,
142
+ ConfigPathMustBeStringError,
143
+ NoConfigFileFoundError,
144
+ InvalidEntrypointError,
145
+ MissingEntrypointError,
146
+ InvalidServicesWithWebError,
147
+ MissingDependencyError,
148
+ InspectAndInspectBrkError,
149
+ InspectorPortError,
150
+ InspectorHostError,
151
+ CannotMapSpecifierToAbsolutePathError,
152
+ NodeInspectorFlagsNotSupportedError,
153
+ FailedToUnlinkManagementApiSocket,
154
+ LogFileNotFound,
155
+ WorkerIsRequired,
156
+ InvalidArgumentError,
157
+ MessagingError
116
158
  }
@@ -1,18 +1,25 @@
1
1
  'use strict'
2
2
 
3
+ const createError = require('@fastify/error')
3
4
  const { BaseGenerator } = require('@platformatic/generators')
4
- const { NoEntryPointError, NoServiceNamedError } = require('./errors')
5
5
  const { existsSync } = require('node:fs')
6
6
  const { join, basename } = require('node:path')
7
7
  const { envObjectToString } = require('@platformatic/generators/lib/utils')
8
8
  const { readFile, readdir, stat } = require('node:fs/promises')
9
- const { ConfigManager } = require('@platformatic/config')
10
- const { platformaticRuntime } = require('../config')
9
+ const { transform } = require('./config')
11
10
  const { getServiceTemplateFromSchemaUrl } = require('@platformatic/generators/lib/utils')
12
11
  const { DotEnvTool } = require('dotenv-tool')
13
- const { getArrayDifference } = require('../utils')
12
+ const { getArrayDifference } = require('./utils')
13
+ const { schema } = require('./schema')
14
14
  const { pathToFileURL } = require('node:url')
15
- const { safeRemove, generateDashedName, DEFAULT_PACKAGE_MANAGER } = require('@platformatic/utils')
15
+ const {
16
+ safeRemove,
17
+ generateDashedName,
18
+ findConfigurationFile,
19
+ loadConfiguration,
20
+ loadConfigurationFile,
21
+ kMetadata
22
+ } = require('@platformatic/utils')
16
23
  const { createRequire } = require('node:module')
17
24
 
18
25
  const wrappableProperties = {
@@ -27,9 +34,17 @@ const wrappableProperties = {
27
34
  }
28
35
 
29
36
  const engines = {
30
- node: '^18.8.0 || >=20.6.0'
37
+ node: '>=22.16.0'
31
38
  }
32
39
 
40
+ const ERROR_PREFIX = 'PLT_RUNTIME_GEN'
41
+
42
+ const NoServiceNamedError = createError(
43
+ `${ERROR_PREFIX}_NO_SERVICE_FOUND`,
44
+ "No service named '%s' has been added to this runtime."
45
+ )
46
+ const NoEntryPointError = createError(`${ERROR_PREFIX}_NO_ENTRYPOINT`, 'No entrypoint had been defined.')
47
+
33
48
  function getRuntimeBaseEnvVars (config) {
34
49
  return {
35
50
  PLT_SERVER_HOSTNAME: '127.0.0.1',
@@ -50,7 +65,6 @@ class RuntimeGenerator extends BaseGenerator {
50
65
  this.services = []
51
66
  this.existingServices = []
52
67
  this.entryPoint = null
53
- this.packageManager = opts.packageManager ?? DEFAULT_PACKAGE_MANAGER
54
68
  }
55
69
 
56
70
  async addService (service, name) {
@@ -86,6 +100,7 @@ class RuntimeGenerator extends BaseGenerator {
86
100
  async generatePackageJson () {
87
101
  const template = {
88
102
  name: `${this.runtimeName}`,
103
+ workspaces: [this.servicesFolder + '/*'],
89
104
  scripts: {
90
105
  dev: this.config.devCommand,
91
106
  build: this.config.buildCommand,
@@ -103,13 +118,8 @@ class RuntimeGenerator extends BaseGenerator {
103
118
  },
104
119
  engines
105
120
  }
106
-
107
- if (this.packageManager === 'npm' || this.packageManager === 'yarn') {
108
- template.workspaces = [this.servicesFolder + '/*']
109
- }
110
-
111
121
  if (this.config.typescript) {
112
- const typescriptVersion = JSON.parse(await readFile(join(__dirname, '..', '..', 'package.json'), 'utf-8'))
122
+ const typescriptVersion = JSON.parse(await readFile(join(__dirname, '..', 'package.json'), 'utf-8'))
113
123
  .devDependencies.typescript
114
124
  template.scripts.clean = 'rm -fr ./dist'
115
125
  template.scripts.build = 'platformatic compile'
@@ -141,21 +151,19 @@ class RuntimeGenerator extends BaseGenerator {
141
151
  return
142
152
  }
143
153
  this._hasCheckedForExistingConfig = true
144
- const existingConfigFile =
145
- this.runtimeConfig ?? (await ConfigManager.findConfigFile(this.targetDirectory, 'runtime'))
154
+ const existingConfigFile = this.runtimeConfig ?? (await findConfigurationFile(this.targetDirectory, 'runtime'))
146
155
  if (existingConfigFile && existsSync(join(this.targetDirectory, existingConfigFile))) {
147
- const configManager = new ConfigManager({
148
- ...platformaticRuntime.configManagerConfig,
149
- source: join(this.targetDirectory, existingConfigFile)
156
+ this.existingConfigRaw = await loadConfigurationFile(join(this.targetDirectory, existingConfigFile))
157
+ this.existingConfig = await loadConfiguration(join(this.targetDirectory, existingConfigFile), schema, {
158
+ transform,
159
+ ignoreProcessEnv: true
150
160
  })
151
- await configManager.parse()
152
161
 
153
- this.existingConfig = configManager.current
154
- this.existingConfigRaw = configManager.currentRaw
155
- this.config.env = configManager.env
156
- this.config.port = configManager.env.PORT
157
- this.entryPoint = configManager.current.services.find(svc => svc.entrypoint)
158
- this.existingServices = configManager.current.services.map(s => s.id)
162
+ const { PLT_ROOT, ...existingEnvironment } = this.existingConfig[kMetadata].env
163
+ this.config.env = existingEnvironment
164
+ this.config.port = this.config.env.PORT
165
+ this.entryPoint = this.existingConfig.services.find(svc => svc.entrypoint)
166
+ this.existingServices = this.existingConfig.services.map(s => s.id)
159
167
 
160
168
  this.updateRuntimeConfig(this.existingConfigRaw)
161
169
  this.updateRuntimeEnv(await readFile(join(this.targetDirectory, '.env'), 'utf-8'))
@@ -218,13 +226,9 @@ class RuntimeGenerator extends BaseGenerator {
218
226
  this.addFile({
219
227
  path: '',
220
228
  file: '.env.sample',
221
- contents: envObjectToString(this.config.defaultEnv)
229
+ contents: envObjectToString(this.config.env)
222
230
  })
223
231
 
224
- if (!this.existingConfig) {
225
- this.addFile({ path: '', file: 'README.md', contents: await readFile(join(__dirname, 'README.md'), 'utf-8') })
226
- }
227
-
228
232
  return {
229
233
  targetDirectory: this.targetDirectory,
230
234
  env: servicesEnv
@@ -362,7 +366,7 @@ class RuntimeGenerator extends BaseGenerator {
362
366
  const dirStat = await stat(currentServicePath)
363
367
  if (dirStat.isDirectory()) {
364
368
  // load the service config
365
- const configFile = await ConfigManager.findConfigFile(currentServicePath)
369
+ const configFile = await findConfigurationFile(currentServicePath)
366
370
  const servicePltJson = JSON.parse(await readFile(join(currentServicePath, configFile), 'utf-8'))
367
371
  // get module to load
368
372
  const template = servicePltJson.module || getServiceTemplateFromSchemaUrl(servicePltJson.$schema)
@@ -410,7 +414,7 @@ class RuntimeGenerator extends BaseGenerator {
410
414
 
411
415
  // delete dependencies
412
416
  const servicePath = join(this.targetDirectory, this.servicesFolder, s.name)
413
- const configFile = await ConfigManager.findConfigFile(servicePath)
417
+ const configFile = await findConfigurationFile(servicePath)
414
418
  const servicePackageJson = JSON.parse(await readFile(join(servicePath, configFile), 'utf-8'))
415
419
  if (servicePackageJson.plugins && servicePackageJson.plugins.packages) {
416
420
  servicePackageJson.plugins.packages.forEach(p => {
@@ -586,7 +590,7 @@ class WrappedGenerator extends BaseGenerator {
586
590
  this.addFile({
587
591
  path: '',
588
592
  file: '.env.sample',
589
- contents: (await this.#readExistingFile('.env.sample', '', '\n')) + envObjectToString(this.config.defaultEnv)
593
+ contents: (await this.#readExistingFile('.env.sample', '', '\n')) + envObjectToString(this.config.env)
590
594
  })
591
595
  }
592
596
 
package/lib/logger.js CHANGED
@@ -5,7 +5,7 @@ const { join } = require('node:path')
5
5
  const { isatty } = require('node:tty')
6
6
  const pino = require('pino')
7
7
  const pretty = require('pino-pretty')
8
- const { buildPinoFormatters, buildPinoTimestamp } = require('@platformatic/utils')
8
+ const { abstractLogger, buildPinoFormatters, buildPinoTimestamp } = require('@platformatic/utils')
9
9
 
10
10
  const customPrettifiers = {
11
11
  name (name, _, obj) {
@@ -79,4 +79,4 @@ async function createLogger (config, runtimeLogsDir) {
79
79
  return [pino(loggerConfig, multiStream), multiStream]
80
80
  }
81
81
 
82
- module.exports = { createLogger }
82
+ module.exports = { abstractLogger, createLogger }
@@ -203,7 +203,7 @@ async function managementApiPlugin (app, opts) {
203
203
  })
204
204
  }
205
205
 
206
- async function startManagementApi (runtime, configManager) {
206
+ async function startManagementApi (runtime, root) {
207
207
  const runtimePID = process.pid
208
208
 
209
209
  try {
@@ -212,7 +212,7 @@ async function startManagementApi (runtime, configManager) {
212
212
  await createDirectory(runtimePIDDir, true)
213
213
  }
214
214
 
215
- const runtimeLogsDir = getRuntimeLogsDir(configManager.dirname, process.pid)
215
+ const runtimeLogsDir = getRuntimeLogsDir(root, process.pid)
216
216
  await createDirectory(runtimeLogsDir, true)
217
217
 
218
218
  let socketPath = null
@@ -77,7 +77,6 @@ async function startPrometheusServer (runtime, opts) {
77
77
  const auth = opts.auth ?? null
78
78
 
79
79
  const promServer = fastify({ name: 'Prometheus server' })
80
- promServer.register(require('@fastify/accepts'))
81
80
 
82
81
  let onRequestHook
83
82
  if (auth) {
@@ -123,12 +122,9 @@ async function startPrometheusServer (runtime, opts) {
123
122
  logLevel: 'warn',
124
123
  onRequest: onRequestHook,
125
124
  handler: async (req, reply) => {
126
- const accepts = req.accepts()
127
- const reqType = !accepts.type('text/plain') && accepts.type('application/json') ? 'json' : 'text'
128
- if (reqType === 'text') {
129
- reply.type('text/plain')
130
- }
131
- return (await runtime.getMetrics(reqType)).metrics
125
+ reply.type('text/plain')
126
+ const { metrics } = await runtime.getMetrics('text')
127
+ return metrics
132
128
  },
133
129
  })
134
130