@platformatic/watt-extra 1.18.0-alpha.2 → 1.18.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/.github/workflows/test.yml +1 -1
- package/lib/watt.js +4 -1
- package/package.json +1 -1
- package/test/next-cache.test.js +79 -0
package/lib/watt.js
CHANGED
|
@@ -586,7 +586,10 @@ class Watt {
|
|
|
586
586
|
const config = runtime.getRuntimeConfig(true)
|
|
587
587
|
|
|
588
588
|
for (const app of config.applications ?? []) {
|
|
589
|
-
|
|
589
|
+
// Older runtimes report the bare capability name, current ones the
|
|
590
|
+
// package name (@platformatic/foundation prefixes it): accept both, or
|
|
591
|
+
// the Next cache adapter and the other Next patches are never applied.
|
|
592
|
+
if (app.type === 'next' || app.type === '@platformatic/next') {
|
|
590
593
|
await this.#configureNextService(runtime, app)
|
|
591
594
|
} else if (
|
|
592
595
|
[
|
package/package.json
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import assert from 'node:assert'
|
|
2
|
+
import { execFileSync } from 'node:child_process'
|
|
3
|
+
import { randomUUID } from 'node:crypto'
|
|
4
|
+
import { existsSync } from 'node:fs'
|
|
5
|
+
import { dirname, join } from 'node:path'
|
|
6
|
+
import { test } from 'node:test'
|
|
7
|
+
import { fileURLToPath } from 'node:url'
|
|
8
|
+
|
|
9
|
+
import { start } from '../index.js'
|
|
10
|
+
import { setUpEnvironment, startICC } from './helper.js'
|
|
11
|
+
|
|
12
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
13
|
+
|
|
14
|
+
// The runtime reports a Next.js application as '@platformatic/next' (older
|
|
15
|
+
// runtimes said 'next'). The Next patches, cache adapter included, must be
|
|
16
|
+
// applied in both cases.
|
|
17
|
+
test('should configure the Next.js cache adapter for @platformatic/next applications', async (t) => {
|
|
18
|
+
const applicationName = 'test-next'
|
|
19
|
+
const applicationId = randomUUID()
|
|
20
|
+
const applicationPath = join(__dirname, 'fixtures', 'runtime-next')
|
|
21
|
+
|
|
22
|
+
// The application starts in production mode, so the fixture needs a build;
|
|
23
|
+
// reuse an existing one to keep local reruns fast.
|
|
24
|
+
if (!existsSync(join(applicationPath, 'web', 'next', '.next', 'BUILD_ID'))) {
|
|
25
|
+
execFileSync(join(__dirname, '..', 'node_modules', '.bin', 'platformatic'), ['build', applicationPath], {
|
|
26
|
+
stdio: 'ignore'
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const clientOpts = {
|
|
31
|
+
host: '127.0.0.1',
|
|
32
|
+
port: 6379,
|
|
33
|
+
username: 'cache-user',
|
|
34
|
+
password: 'cache-pass',
|
|
35
|
+
keyPrefix: `${applicationId}:`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const icc = await startICC(t, {
|
|
39
|
+
applicationId,
|
|
40
|
+
applicationName,
|
|
41
|
+
controlPlaneResponse: {
|
|
42
|
+
applicationId,
|
|
43
|
+
applicationName,
|
|
44
|
+
deploymentVersion: 'v-next',
|
|
45
|
+
enableOpenTelemetry: false,
|
|
46
|
+
iccServices: {},
|
|
47
|
+
httpCache: { clientOpts },
|
|
48
|
+
config: {}
|
|
49
|
+
},
|
|
50
|
+
port: 3001
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
setUpEnvironment({
|
|
54
|
+
PLT_APP_NAME: applicationName,
|
|
55
|
+
PLT_APP_DIR: applicationPath,
|
|
56
|
+
PLT_ICC_URL: icc.iccUrl,
|
|
57
|
+
PLT_APP_PORT: 3043,
|
|
58
|
+
PLT_METRICS_PORT: 9092
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const app = await start()
|
|
62
|
+
|
|
63
|
+
t.after(async () => {
|
|
64
|
+
await app.close()
|
|
65
|
+
await icc.close()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const runtimeConfig = app.watt.runtime.getRuntimeConfig(true)
|
|
69
|
+
const nextApplication = runtimeConfig.applications.find((application) => application.id === 'next')
|
|
70
|
+
assert.strictEqual(nextApplication.type, '@platformatic/next')
|
|
71
|
+
|
|
72
|
+
const nextConfig = await app.watt.runtime.getApplicationConfig('next')
|
|
73
|
+
assert.deepStrictEqual(nextConfig.cache, {
|
|
74
|
+
adapter: 'valkey',
|
|
75
|
+
url: 'valkey://cache-user:cache-pass@127.0.0.1:6379',
|
|
76
|
+
prefix: `${applicationId}:`,
|
|
77
|
+
maxTTL: 604800
|
|
78
|
+
})
|
|
79
|
+
})
|