@platformatic/basic 2.0.0-alpha.4 → 2.0.0-alpha.5

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 (103) hide show
  1. package/NOTICE +13 -0
  2. package/README.md +13 -0
  3. package/config.d.ts +1 -149
  4. package/index.js +60 -87
  5. package/lib/base.js +4 -4
  6. package/lib/schema.js +26 -33
  7. package/lib/utils.js +1 -5
  8. package/lib/worker/child-manager.js +12 -0
  9. package/lib/worker/child-process.js +66 -0
  10. package/package.json +6 -13
  11. package/schema.json +2 -512
  12. package/test/helper.js +38 -9
  13. package/lib/next.js +0 -105
  14. package/lib/server.js +0 -134
  15. package/lib/vite.js +0 -105
  16. package/lib/worker/next-loader.js +0 -137
  17. package/test/express.test.js +0 -34
  18. package/test/fastify.test.js +0 -34
  19. package/test/fixtures/express/no-build/index.js +0 -16
  20. package/test/fixtures/express/no-build/package.json +0 -7
  21. package/test/fixtures/express/no-build/platformatic.app.json +0 -3
  22. package/test/fixtures/express/no-build/platformatic.as-entrypoint.runtime.json +0 -19
  23. package/test/fixtures/express/no-build/platformatic.no-entrypoint.runtime.json +0 -16
  24. package/test/fixtures/express/with-build/index.js +0 -17
  25. package/test/fixtures/express/with-build/package.json +0 -7
  26. package/test/fixtures/express/with-build/platformatic.app.json +0 -3
  27. package/test/fixtures/express/with-build/platformatic.as-entrypoint.runtime.json +0 -19
  28. package/test/fixtures/express/with-build/platformatic.no-entrypoint.runtime.json +0 -16
  29. package/test/fixtures/fastify/no-build/index.js +0 -14
  30. package/test/fixtures/fastify/no-build/package.json +0 -7
  31. package/test/fixtures/fastify/no-build/platformatic.app.json +0 -3
  32. package/test/fixtures/fastify/no-build/platformatic.as-entrypoint.runtime.json +0 -19
  33. package/test/fixtures/fastify/no-build/platformatic.no-entrypoint.runtime.json +0 -16
  34. package/test/fixtures/fastify/with-build/index.js +0 -15
  35. package/test/fixtures/fastify/with-build/package.json +0 -7
  36. package/test/fixtures/fastify/with-build/platformatic.app.json +0 -3
  37. package/test/fixtures/fastify/with-build/platformatic.as-entrypoint.runtime.json +0 -19
  38. package/test/fixtures/fastify/with-build/platformatic.no-entrypoint.runtime.json +0 -16
  39. package/test/fixtures/next/composer-autodetect-prefix/next.config.mjs +0 -5
  40. package/test/fixtures/next/composer-autodetect-prefix/package.json +0 -15
  41. package/test/fixtures/next/composer-autodetect-prefix/platformatic.application.json +0 -8
  42. package/test/fixtures/next/composer-autodetect-prefix/platformatic.runtime.json +0 -21
  43. package/test/fixtures/next/composer-autodetect-prefix/src/app/layout.js +0 -7
  44. package/test/fixtures/next/composer-autodetect-prefix/src/app/page.js +0 -5
  45. package/test/fixtures/next/composer-with-prefix/next.config.js +0 -1
  46. package/test/fixtures/next/composer-with-prefix/package.json +0 -15
  47. package/test/fixtures/next/composer-with-prefix/platformatic.application.json +0 -11
  48. package/test/fixtures/next/composer-with-prefix/platformatic.runtime.json +0 -21
  49. package/test/fixtures/next/composer-with-prefix/src/app/layout.js +0 -7
  50. package/test/fixtures/next/composer-with-prefix/src/app/page.js +0 -5
  51. package/test/fixtures/next/composer-without-prefix/next.config.mjs +0 -3
  52. package/test/fixtures/next/composer-without-prefix/package.json +0 -15
  53. package/test/fixtures/next/composer-without-prefix/platformatic.application.json +0 -8
  54. package/test/fixtures/next/composer-without-prefix/platformatic.runtime.json +0 -21
  55. package/test/fixtures/next/composer-without-prefix/src/app/layout.js +0 -7
  56. package/test/fixtures/next/composer-without-prefix/src/app/page.js +0 -5
  57. package/test/fixtures/next/standalone/next.config.mjs +0 -3
  58. package/test/fixtures/next/standalone/package.json +0 -15
  59. package/test/fixtures/next/standalone/platformatic.runtime.json +0 -18
  60. package/test/fixtures/next/standalone/src/app/layout.js +0 -7
  61. package/test/fixtures/next/standalone/src/app/page.js +0 -5
  62. package/test/fixtures/nodejs/no-build/index.js +0 -21
  63. package/test/fixtures/nodejs/no-build/package.json +0 -7
  64. package/test/fixtures/nodejs/no-build/platformatic.app.json +0 -3
  65. package/test/fixtures/nodejs/no-build/platformatic.as-entrypoint.runtime.json +0 -19
  66. package/test/fixtures/nodejs/no-build/platformatic.no-entrypoint.runtime.json +0 -16
  67. package/test/fixtures/nodejs/no-configuration/index.js +0 -21
  68. package/test/fixtures/nodejs/no-configuration/platformatic.as-entrypoint.runtime.json +0 -18
  69. package/test/fixtures/nodejs/no-configuration/platformatic.no-entrypoint.runtime.json +0 -16
  70. package/test/fixtures/nodejs/with-build/index.js +0 -20
  71. package/test/fixtures/nodejs/with-build/package.json +0 -7
  72. package/test/fixtures/nodejs/with-build/platformatic.app.json +0 -3
  73. package/test/fixtures/nodejs/with-build/platformatic.as-entrypoint.runtime.json +0 -19
  74. package/test/fixtures/nodejs/with-build/platformatic.no-entrypoint.runtime.json +0 -16
  75. package/test/fixtures/platformatic-composer/platformatic.composer.json +0 -20
  76. package/test/fixtures/platformatic-composer/platformatic.no-prefix.composer.json +0 -23
  77. package/test/fixtures/platformatic-composer/plugin.js +0 -9
  78. package/test/fixtures/platformatic-service/platformatic.service.json +0 -15
  79. package/test/fixtures/platformatic-service/plugin.js +0 -12
  80. package/test/fixtures/vite/composer-autodetect-prefix/custom.vite.config.js +0 -3
  81. package/test/fixtures/vite/composer-autodetect-prefix/index.html +0 -13
  82. package/test/fixtures/vite/composer-autodetect-prefix/main.js +0 -3
  83. package/test/fixtures/vite/composer-autodetect-prefix/package.json +0 -14
  84. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.application.json +0 -11
  85. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.runtime.json +0 -21
  86. package/test/fixtures/vite/composer-with-prefix/index.html +0 -13
  87. package/test/fixtures/vite/composer-with-prefix/main.js +0 -3
  88. package/test/fixtures/vite/composer-with-prefix/package.json +0 -14
  89. package/test/fixtures/vite/composer-with-prefix/platformatic.application.json +0 -11
  90. package/test/fixtures/vite/composer-with-prefix/platformatic.runtime.json +0 -21
  91. package/test/fixtures/vite/composer-without-prefix/index.html +0 -13
  92. package/test/fixtures/vite/composer-without-prefix/main.js +0 -3
  93. package/test/fixtures/vite/composer-without-prefix/package.json +0 -14
  94. package/test/fixtures/vite/composer-without-prefix/platformatic.application.json +0 -8
  95. package/test/fixtures/vite/composer-without-prefix/platformatic.runtime.json +0 -21
  96. package/test/fixtures/vite/standalone/custom.vite.config.js +0 -3
  97. package/test/fixtures/vite/standalone/index.html +0 -13
  98. package/test/fixtures/vite/standalone/main.js +0 -3
  99. package/test/fixtures/vite/standalone/package.json +0 -14
  100. package/test/fixtures/vite/standalone/platformatic.runtime.json +0 -18
  101. package/test/next.test.js +0 -85
  102. package/test/node.test.js +0 -66
  103. package/test/vite.test.js +0 -89
package/lib/next.js DELETED
@@ -1,105 +0,0 @@
1
- import { once } from 'node:events'
2
- import { readFile } from 'node:fs/promises'
3
- import { createRequire } from 'node:module'
4
- import { dirname, resolve as pathResolve } from 'node:path'
5
- import { pathToFileURL } from 'node:url'
6
- import { satisfies } from 'semver'
7
- import { BaseStackable } from './base.js'
8
- import { UnsupportedVersion } from './errors.js'
9
- import { importFile } from './utils.js'
10
- import { ChildManager } from './worker/child-manager.js'
11
-
12
- const supportedVersions = '^14.0.0'
13
-
14
- export class NextStackable extends BaseStackable {
15
- #basePath
16
- #next
17
- #manager
18
-
19
- constructor (options, root, configManager) {
20
- super(options, root, configManager)
21
- this.type = 'next'
22
- }
23
-
24
- async init () {
25
- globalThis[Symbol.for('plt.runtime.itc')].handle('getServiceMeta', this.getMeta.bind(this))
26
-
27
- this.#next = pathResolve(dirname(createRequire(this.root).resolve('next')), '../..')
28
- const nextPackage = JSON.parse(await readFile(pathResolve(this.#next, 'package.json')))
29
-
30
- if (!satisfies(nextPackage.version, supportedVersions)) {
31
- throw new UnsupportedVersion('next', nextPackage.version, supportedVersions)
32
- }
33
- }
34
-
35
- async start () {
36
- // Make this idempotent
37
- if (this.url) {
38
- return this.url
39
- }
40
-
41
- const config = this.configManager.current
42
- const require = createRequire(this.root)
43
- const nextRoot = require.resolve('next')
44
-
45
- const { hostname, port } = this.serverConfig ?? {}
46
- const serverOptions = {
47
- host: hostname || '127.0.0.1',
48
- port: port || 0,
49
- }
50
-
51
- this.#basePath = config.application?.base
52
- ? `/${config.application?.base}`.replaceAll(/\/+/g, '/').replace(/\/$/, '')
53
- : ''
54
-
55
- this.#manager = new ChildManager({
56
- loader: new URL('./worker/next-loader.js', import.meta.url),
57
- context: {
58
- // Always use URL to avoid serialization problem in Windows
59
- root: pathToFileURL(this.root),
60
- basePath: this.#basePath,
61
- logger: { id: this.id, level: this.logger.level },
62
- },
63
- })
64
-
65
- this.#manager.on('config', config => {
66
- this.#basePath = config.basePath.replace(/(^\/)|(\/$)/g, '')
67
- })
68
-
69
- const promise = once(this.#manager, 'url')
70
- await this.#startNext(nextRoot, serverOptions)
71
- this.url = (await promise)[0]
72
- }
73
-
74
- async stop () {
75
- const exitPromise = once(this.#manager, 'exit')
76
-
77
- this.#manager.close()
78
- await exitPromise
79
- }
80
-
81
- async getWatchConfig () {
82
- return {
83
- enabled: false,
84
- }
85
- }
86
-
87
- getMeta () {
88
- return {
89
- composer: {
90
- tcp: true,
91
- url: this.url,
92
- prefix: this.#basePath,
93
- wantsAbsoluteUrls: true,
94
- },
95
- }
96
- }
97
-
98
- async #startNext (nextRoot, serverOptions) {
99
- const { nextDev } = await importFile(pathResolve(this.#next, './dist/cli/next-dev.js'))
100
-
101
- this.#manager.inject()
102
- await nextDev(serverOptions, 'default', this.root)
103
- this.#manager.eject()
104
- }
105
- }
package/lib/server.js DELETED
@@ -1,134 +0,0 @@
1
- import inject from 'light-my-request'
2
- import { Server } from 'node:http'
3
- import { resolve as pathResolve } from 'node:path'
4
- import { BaseStackable } from './base.js'
5
- import { getServerUrl, importFile, injectViaRequest, isFastify } from './utils.js'
6
- import { createServerListener } from './worker/server-listener.js'
7
-
8
- export class ServerStackable extends BaseStackable {
9
- #entrypoint
10
- #hadEntrypointField
11
- #module
12
- #app
13
- #server
14
- #dispatcher
15
- #isFastify
16
-
17
- constructor (options, root, configManager, entrypoint, hadEntrypointField) {
18
- super(options, root, configManager)
19
- this.#entrypoint = entrypoint
20
- this.#hadEntrypointField = hadEntrypointField
21
- }
22
-
23
- async start ({ listen }) {
24
- // Make this idempotent
25
- if (this.url) {
26
- return this.url
27
- }
28
-
29
- // Listen if entrypoint
30
- if (this.#app && listen) {
31
- await this.#listen()
32
- return this.url
33
- }
34
-
35
- // Require the application
36
- if (!this.#hadEntrypointField) {
37
- this.logger.warn(
38
- `The service ${this.id} had no valid entrypoint defined in the package.json file. Falling back to the file ${this.#entrypoint}.`
39
- )
40
- }
41
-
42
- // The server promise must be created before requiring the entrypoint even if it's not going to be used
43
- // at all. Otherwise there is chance we miss the listen event.
44
- const serverPromise = createServerListener()
45
- this.#module = await importFile(pathResolve(this.root, this.#entrypoint))
46
- this.#module = this.#module.default || this.#module
47
-
48
- // Deal with application
49
- if (typeof this.#module.build === 'function') {
50
- // We have build function, this Stackable will not use HTTP unless it is the entrypoint
51
- serverPromise.cancel()
52
-
53
- this.#app = await this.#module.build()
54
- this.#isFastify = isFastify(this.#app)
55
-
56
- if (this.#isFastify) {
57
- await this.#app.ready()
58
- } else if (this.#app instanceof Server) {
59
- this.#server = this.#app
60
- this.#dispatcher = this.#server.listeners('request')[0]
61
- }
62
- } else {
63
- // User blackbox function, we wait for it to listen on a port
64
- this.#server = await serverPromise
65
- this.url = getServerUrl(this.#server)
66
- }
67
-
68
- return this.url
69
- }
70
-
71
- async stop () {
72
- if (this.#isFastify) {
73
- return this.#app.close()
74
- }
75
-
76
- if (this.#server) {
77
- if (!this.#server.listening) {
78
- return
79
- }
80
-
81
- return new Promise((resolve, reject) => {
82
- this.#server.close(error => {
83
- if (error) {
84
- return reject(error)
85
- }
86
-
87
- resolve(error)
88
- })
89
- })
90
- }
91
- }
92
-
93
- async inject (injectParams, onInject) {
94
- let res
95
- if (this.#isFastify) {
96
- res = await this.#app.inject(injectParams, onInject)
97
- } else if (this.#dispatcher) {
98
- res = await inject(this.#dispatcher, injectParams, onInject)
99
- } else {
100
- res = await injectViaRequest(this.url, injectParams, onInject)
101
- }
102
-
103
- if (onInject) {
104
- return
105
- }
106
-
107
- // Since inject might be called from the main thread directly via ITC, let's clean it up
108
- const { statusCode, headers, body, payload, rawPayload } = res
109
-
110
- return { statusCode, headers, body, payload, rawPayload }
111
- }
112
-
113
- async #listen () {
114
- const serverOptions = this.serverConfig
115
-
116
- if (this.#isFastify) {
117
- await this.#app.listen({ host: serverOptions?.hostname || '127.0.0.1', port: serverOptions?.port || 0 })
118
- this.url = getServerUrl(this.#app.server)
119
- } else {
120
- // Express / Node
121
- this.#server = await new Promise((resolve, reject) => {
122
- return this.#app
123
- .listen({ host: serverOptions?.hostname || '127.0.0.1', port: serverOptions?.port || 0 }, function () {
124
- resolve(this)
125
- })
126
- .on('error', reject)
127
- })
128
-
129
- this.url = getServerUrl(this.#server)
130
- }
131
-
132
- return this.url
133
- }
134
- }
package/lib/vite.js DELETED
@@ -1,105 +0,0 @@
1
- import { createRequire } from 'node:module'
2
- import { dirname, resolve as pathResolve } from 'node:path'
3
- import { satisfies } from 'semver'
4
- import { BaseStackable } from './base.js'
5
- import { getServerUrl, importFile } from './utils.js'
6
- import { createServerListener } from './worker/server-listener.js'
7
-
8
- import { readFile } from 'node:fs/promises'
9
- import { UnsupportedVersion } from './errors.js'
10
-
11
- const supportedVersions = '^5.0.0'
12
-
13
- export class ViteStackable extends BaseStackable {
14
- #vite
15
- #app
16
- #server
17
- #basePath
18
-
19
- constructor (options, root, configManager) {
20
- super(options, root, configManager)
21
- this.type = 'vite'
22
- }
23
-
24
- async init () {
25
- globalThis[Symbol.for('plt.runtime.itc')].handle('getServiceMeta', this.getMeta.bind(this))
26
-
27
- this.#vite = dirname(createRequire(this.root).resolve('vite'))
28
- const vitePackage = JSON.parse(await readFile(pathResolve(this.#vite, 'package.json')))
29
-
30
- if (!satisfies(vitePackage.version, supportedVersions)) {
31
- throw new UnsupportedVersion('vite', vitePackage.version, supportedVersions)
32
- }
33
- }
34
-
35
- async start () {
36
- // Make this idempotent
37
- if (this.url) {
38
- return this.url
39
- }
40
-
41
- const config = this.configManager.current
42
-
43
- // Prepare options
44
- const { hostname, port, https, cors } = this.serverConfig ?? {}
45
- const configFile = config.vite?.configFile ? pathResolve(this.root, config.vite?.configFile) : undefined
46
- const basePath = config.application?.base
47
- ? `/${config.application?.base}`.replaceAll(/\/+/g, '/').replace(/\/$/, '')
48
- : undefined
49
-
50
- const serverOptions = {
51
- host: hostname || '127.0.0.1',
52
- port: port || 0,
53
- strictPort: false,
54
- https,
55
- cors,
56
- origin: 'http://localhost',
57
- hmr: true,
58
- }
59
-
60
- // Require Vite
61
- const serverPromise = createServerListener()
62
- const { createServer } = await importFile(pathResolve(this.#vite, 'dist/node/index.js'))
63
-
64
- // Create the server and listen
65
- this.#app = await createServer({
66
- root: this.root,
67
- base: basePath,
68
- mode: 'development',
69
- configFile,
70
- logLevel: this.logger.level,
71
- clearScreen: false,
72
- optimizeDeps: { force: false },
73
- server: serverOptions,
74
- })
75
-
76
- await this.#app.listen()
77
- this.#server = await serverPromise
78
- this.url = getServerUrl(this.#server)
79
- }
80
-
81
- async stop () {
82
- return this.#app.close()
83
- }
84
-
85
- async getWatchConfig () {
86
- return {
87
- enabled: false,
88
- }
89
- }
90
-
91
- getMeta () {
92
- if (!this.#basePath) {
93
- this.#basePath = this.#app.config.base.replace(/(^\/)|(\/$)/g, '')
94
- }
95
-
96
- return {
97
- composer: {
98
- tcp: true,
99
- url: this.url,
100
- prefix: this.#basePath,
101
- wantsAbsoluteUrls: true,
102
- },
103
- }
104
- }
105
- }
@@ -1,137 +0,0 @@
1
- import generate from '@babel/generator'
2
- import { parse } from '@babel/parser'
3
- import traverse from '@babel/traverse'
4
- import {
5
- blockStatement,
6
- functionDeclaration,
7
- identifier,
8
- restElement,
9
- returnStatement,
10
- variableDeclaration,
11
- variableDeclarator,
12
- } from '@babel/types'
13
- import { readFile } from 'node:fs/promises'
14
-
15
- const originalId = '__pltOriginalNextConfig'
16
-
17
- let candidates
18
- let basePath
19
-
20
- function parseSingleExpression (expr) {
21
- return parse(expr, { allowAwaitOutsideFunction: true }).program.body[0]
22
- }
23
-
24
- /*
25
- Generates:
26
- async function (...args) {
27
- let __pltOriginalNextConfig = $ORIGINAL;
28
-
29
- if (typeof __pltOriginalNextConfig === 'function') {
30
- __pltOriginalNextConfig = await __pltOriginalNextConfig(...args);
31
- }
32
-
33
- if(typeof __pltOriginalNextConfig === 'undefined') {
34
- __pltOriginalNextConfig.basePath = basePath
35
- }
36
-
37
- return __pltOriginalNextConfig,
38
- basePath: $BASEPATH
39
- };
40
- }
41
- */
42
- function createEvaluatorWrapperFunction (original) {
43
- return functionDeclaration(
44
- null,
45
- [restElement(identifier('args'))],
46
- blockStatement([
47
- variableDeclaration('let', [variableDeclarator(identifier(originalId), original)]),
48
- parseSingleExpression(
49
- `if (typeof ${originalId} === 'function') { ${originalId} = await ${originalId}(...args) }`
50
- ),
51
- parseSingleExpression(
52
- `if (typeof ${originalId}.basePath === 'undefined') { ${originalId}.basePath = "${basePath}" }`
53
- ),
54
- parseSingleExpression(`globalThis[Symbol.for('plt.children.itc')].notify('config', ${originalId})`),
55
- returnStatement(identifier(originalId)),
56
- ]),
57
- false,
58
- true
59
- )
60
- }
61
-
62
- function transformCJS (source) {
63
- const ast = parse(source.toString(), { sourceType: 'module' })
64
-
65
- // Manipulate the AST
66
- traverse.default(ast, {
67
- AssignmentExpression (path) {
68
- const { left, right } = path.node
69
-
70
- // module.exports = $EXPRESSION
71
- if (left.object.name === 'module' && left.property.name === 'exports') {
72
- path.node.right = createEvaluatorWrapperFunction(right)
73
- path.skip()
74
- }
75
- },
76
- })
77
-
78
- return generate.default(ast).code
79
- }
80
-
81
- function transformESM (source) {
82
- const ast = parse(source.toString(), { sourceType: 'module' })
83
-
84
- // Manipulate the AST
85
- traverse.default(ast, {
86
- ExportDefaultDeclaration (path) {
87
- const declaration = path.node.declaration
88
-
89
- // export default [async] function
90
- if (path.node.declaration.type === 'FunctionDeclaration') {
91
- path.insertBefore(
92
- functionDeclaration(
93
- identifier(originalId + 'Function'),
94
- declaration.params,
95
- declaration.body,
96
- declaration.generator,
97
- declaration.async
98
- )
99
- )
100
-
101
- path.node.declaration = createEvaluatorWrapperFunction(identifier(originalId + 'Function'))
102
- } else {
103
- // export default $EXPRESSION
104
- path.node.declaration = createEvaluatorWrapperFunction(declaration)
105
- }
106
- },
107
- })
108
-
109
- return generate.default(ast).code
110
- }
111
-
112
- export function initialize (data) {
113
- // Keep in sync with https://github.com/vercel/next.js/blob/main/packages/next/src/shared/lib/constants.ts
114
- candidates = ['./next.config.js', './next.config.mjs'].map(c => new URL(c, data.root + '/').toString())
115
- basePath = data.basePath ?? ''
116
- }
117
-
118
- export async function load (url, context, nextLoad) {
119
- // Load the original file
120
- const result = await nextLoad(url, context)
121
-
122
- if (!url.startsWith('file:')) {
123
- return result
124
- }
125
-
126
- if (!candidates.includes(url)) {
127
- return result
128
- }
129
-
130
- if (result.format === 'commonjs') {
131
- result.source = transformCJS(result.source ?? (await readFile(new URL(result.responseURL ?? url), 'utf-8')))
132
- } else {
133
- result.source = transformESM(result.source)
134
- }
135
-
136
- return result
137
- }
@@ -1,34 +0,0 @@
1
- import { ifError } from 'node:assert'
2
- import { test } from 'node:test'
3
- import { createRuntime, verifyJSONViaHTTP, verifyJSONViaInject } from './helper.js'
4
-
5
- test('can detect and start an express application with no build function defined', async t => {
6
- const { runtime, url } = await createRuntime(t, 'express/no-build/platformatic.as-entrypoint.runtime.json')
7
-
8
- await verifyJSONViaHTTP(url, '/direct', 200, { ok: true })
9
- await verifyJSONViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
10
- })
11
-
12
- test('can detect and start an express application with no build function and when not the entrypoint', async t => {
13
- const { runtime, url } = await createRuntime(t, 'express/no-build/platformatic.no-entrypoint.runtime.json')
14
-
15
- await verifyJSONViaHTTP(url, '/mesh', 200, { ok: true })
16
- await verifyJSONViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
17
- })
18
-
19
- test('can detect and start an express application with build function defined', async t => {
20
- const { runtime, url } = await createRuntime(t, 'express/with-build/platformatic.as-entrypoint.runtime.json')
21
-
22
- await verifyJSONViaHTTP(url, '/direct', 200, { ok: true })
23
- await verifyJSONViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
24
- })
25
-
26
- test('can detect and start an express applicationwith build function defined and when not the entrypoint', async t => {
27
- const { runtime, url } = await createRuntime(t, 'express/no-build/platformatic.no-entrypoint.runtime.json')
28
-
29
- await verifyJSONViaHTTP(url, '/mesh', 200, { ok: true })
30
- await verifyJSONViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
31
-
32
- const details = await runtime.getServiceDetails('internal')
33
- ifError(details.url)
34
- })
@@ -1,34 +0,0 @@
1
- import { ifError } from 'node:assert'
2
- import { test } from 'node:test'
3
- import { createRuntime, verifyJSONViaHTTP, verifyJSONViaInject } from './helper.js'
4
-
5
- test('can detect and start a fastify application with no build function defined', async t => {
6
- const { runtime, url } = await createRuntime(t, 'fastify/no-build/platformatic.as-entrypoint.runtime.json')
7
-
8
- await verifyJSONViaHTTP(url, '/direct', 200, { ok: true })
9
- await verifyJSONViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
10
- })
11
-
12
- test('can detect and start a fastify application with no build function and when not the entrypoint', async t => {
13
- const { runtime, url } = await createRuntime(t, 'fastify/no-build/platformatic.no-entrypoint.runtime.json')
14
-
15
- await verifyJSONViaHTTP(url, '/mesh', 200, { ok: true })
16
- await verifyJSONViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
17
- })
18
-
19
- test('can detect and start a fastify application with build function defined', async t => {
20
- const { runtime, url } = await createRuntime(t, 'fastify/with-build/platformatic.as-entrypoint.runtime.json')
21
-
22
- await verifyJSONViaHTTP(url, '/direct', 200, { ok: true })
23
- await verifyJSONViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
24
- })
25
-
26
- test('can detect and start a fastify application with build function defined and when not the entrypoint', async t => {
27
- const { runtime, url } = await createRuntime(t, 'fastify/no-build/platformatic.no-entrypoint.runtime.json')
28
-
29
- await verifyJSONViaHTTP(url, '/mesh', 200, { ok: true })
30
- await verifyJSONViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
31
-
32
- const details = await runtime.getServiceDetails('internal')
33
- ifError(details.url)
34
- })
@@ -1,16 +0,0 @@
1
- import express from 'express'
2
-
3
- const app = express()
4
-
5
- app.get('/direct', (req, res) => {
6
- res.send({ ok: true })
7
- })
8
-
9
- app.get('/internal', (req, res) => {
10
- fetch('http://main.plt.local/direct')
11
- .then(response => response.json())
12
- .then(res.json.bind(res))
13
- })
14
-
15
- // This would likely fail if our code doesn't work
16
- app.listen(1)
@@ -1,7 +0,0 @@
1
- {
2
- "main": "index.js",
3
- "type": "module",
4
- "dependencies": {
5
- "express": "^4.19.2"
6
- }
7
- }
@@ -1,3 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json"
3
- }
@@ -1,19 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": false,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "error"
10
- }
11
- },
12
- "services": [
13
- {
14
- "id": "main",
15
- "path": ".",
16
- "config": "platformatic.app.json"
17
- }
18
- ]
19
- }
@@ -1,16 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": false,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "error"
10
- }
11
- },
12
- "services": [
13
- { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
- { "id": "internal", "path": ".", "config": "platformatic.app.json" }
15
- ]
16
- }
@@ -1,17 +0,0 @@
1
- import express from 'express'
2
-
3
- export function build () {
4
- const app = express()
5
-
6
- app.get('/direct', (req, res) => {
7
- res.send({ ok: true })
8
- })
9
-
10
- app.get('/internal', (req, res) => {
11
- fetch('http://main.plt.local/direct')
12
- .then(response => response.json())
13
- .then(res.json.bind(res))
14
- })
15
-
16
- return app
17
- }
@@ -1,7 +0,0 @@
1
- {
2
- "main": "index.js",
3
- "type": "module",
4
- "dependencies": {
5
- "express": "^4.19.2"
6
- }
7
- }
@@ -1,3 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/basic/1.52.0.json"
3
- }
@@ -1,19 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": false,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "error"
10
- }
11
- },
12
- "services": [
13
- {
14
- "id": "main",
15
- "path": ".",
16
- "config": "platformatic.app.json"
17
- }
18
- ]
19
- }
@@ -1,16 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": false,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "error"
10
- }
11
- },
12
- "services": [
13
- { "id": "main", "path": "../../platformatic-service", "config": "platformatic.service.json" },
14
- { "id": "internal", "path": ".", "config": "platformatic.app.json" }
15
- ]
16
- }