@zukhruf/nx 0.8.39 → 0.8.40
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/README.md +54 -32
- package/dist/generators/auth/files.d.ts +2 -2
- package/dist/generators/auth/files.d.ts.map +1 -1
- package/dist/generators/auth/files.js +21 -20
- package/dist/generators/auth/files.js.map +1 -1
- package/dist/generators/auth/generator.d.ts.map +1 -1
- package/dist/generators/auth/generator.js +13 -17
- package/dist/generators/auth/generator.js.map +1 -1
- package/dist/generators/dokploy/files.d.ts.map +1 -1
- package/dist/generators/dokploy/files.js +16 -1
- package/dist/generators/dokploy/files.js.map +1 -1
- package/dist/generators/env-file.d.ts +8 -0
- package/dist/generators/env-file.d.ts.map +1 -0
- package/dist/generators/env-file.js +13 -0
- package/dist/generators/env-file.js.map +1 -0
- package/dist/generators/init/files.js +2 -2
- package/dist/generators/init/nx-json.d.ts +7 -0
- package/dist/generators/init/nx-json.d.ts.map +1 -1
- package/dist/generators/init/nx-json.js +19 -1
- package/dist/generators/init/nx-json.js.map +1 -1
- package/dist/generators/node-app/files.d.ts +3 -3
- package/dist/generators/node-app/files.d.ts.map +1 -1
- package/dist/generators/node-app/files.js +48 -35
- package/dist/generators/node-app/files.js.map +1 -1
- package/dist/generators/node-app/generator.js +7 -23
- package/dist/generators/node-app/generator.js.map +1 -1
- package/dist/generators/pair/files.d.ts +11 -2
- package/dist/generators/pair/files.d.ts.map +1 -1
- package/dist/generators/pair/files.js +51 -34
- package/dist/generators/pair/files.js.map +1 -1
- package/dist/generators/pair/generator.d.ts.map +1 -1
- package/dist/generators/pair/generator.js +22 -8
- package/dist/generators/pair/generator.js.map +1 -1
- package/dist/generators/portless-env.d.ts +14 -0
- package/dist/generators/portless-env.d.ts.map +1 -0
- package/dist/generators/portless-env.js +26 -0
- package/dist/generators/portless-env.js.map +1 -0
- package/dist/generators/prisma/files.d.ts.map +1 -1
- package/dist/generators/prisma/files.js +2 -0
- package/dist/generators/prisma/files.js.map +1 -1
- package/dist/generators/prisma/generator.d.ts +35 -1
- package/dist/generators/prisma/generator.d.ts.map +1 -1
- package/dist/generators/prisma/generator.js +57 -36
- package/dist/generators/prisma/generator.js.map +1 -1
- package/dist/generators/react-app/generator.js +10 -20
- package/dist/generators/react-app/generator.js.map +1 -1
- package/dist/generators/ui-package/files.d.ts.map +1 -1
- package/dist/generators/ui-package/files.js +7 -8
- package/dist/generators/ui-package/files.js.map +1 -1
- package/dist/generators/ui-package/generator.d.ts.map +1 -1
- package/dist/generators/ui-package/generator.js +3 -1
- package/dist/generators/ui-package/generator.js.map +1 -1
- package/dist/migrations/update-0-8-40/add-local-postgres.d.ts +14 -0
- package/dist/migrations/update-0-8-40/add-local-postgres.d.ts.map +1 -0
- package/dist/migrations/update-0-8-40/add-local-postgres.js +125 -0
- package/dist/migrations/update-0-8-40/add-local-postgres.js.map +1 -0
- package/dist/migrations/update-0-8-40/add-portless-proxy-env.d.ts +9 -0
- package/dist/migrations/update-0-8-40/add-portless-proxy-env.d.ts.map +1 -0
- package/dist/migrations/update-0-8-40/add-portless-proxy-env.js +21 -0
- package/dist/migrations/update-0-8-40/add-portless-proxy-env.js.map +1 -0
- package/dist/migrations/update-0-8-40/add-prisma-client-inputs.d.ts +11 -0
- package/dist/migrations/update-0-8-40/add-prisma-client-inputs.d.ts.map +1 -0
- package/dist/migrations/update-0-8-40/add-prisma-client-inputs.js +20 -0
- package/dist/migrations/update-0-8-40/add-prisma-client-inputs.js.map +1 -0
- package/dist/migrations/update-0-8-40/node-env-production.d.ts +13 -0
- package/dist/migrations/update-0-8-40/node-env-production.d.ts.map +1 -0
- package/dist/migrations/update-0-8-40/node-env-production.js +189 -0
- package/dist/migrations/update-0-8-40/node-env-production.js.map +1 -0
- package/dist/migrations/workspace.d.ts +31 -0
- package/dist/migrations/workspace.d.ts.map +1 -0
- package/dist/migrations/workspace.js +53 -0
- package/dist/migrations/workspace.js.map +1 -0
- package/migrations.json +24 -0
- package/package.json +51 -3
- package/release.json +30 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds `KEY=value` to an env file that has no line for the key. A line that is
|
|
3
|
+
* there keeps its value. A missing file gets the one line. The prisma and auth
|
|
4
|
+
* generators and the migrations use it (ADR 0014 decision 12, ADR 0017).
|
|
5
|
+
*/
|
|
6
|
+
export function addEnvEntry(tree, path, key, value) {
|
|
7
|
+
const content = tree.read(path, 'utf-8') ?? '';
|
|
8
|
+
if (new RegExp(`^${key}=`, 'm').test(content))
|
|
9
|
+
return;
|
|
10
|
+
const separator = content === '' || content.endsWith('\n') ? '' : '\n';
|
|
11
|
+
tree.write(path, `${content}${separator}${key}=${value}\n`);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=env-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-file.js","sourceRoot":"","sources":["../../src/generators/env-file.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CACzB,IAAU,EACV,IAAY,EACZ,GAAW,EACX,KAAa;IAEb,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/C,IAAI,IAAI,MAAM,CAAC,IAAI,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO;IACtD,MAAM,SAAS,GAAG,OAAO,KAAK,EAAE,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACvE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,OAAO,GAAG,SAAS,GAAG,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -226,8 +226,8 @@ await preCommit([
|
|
|
226
226
|
`,
|
|
227
227
|
'.husky/pre-push.ts': `#!/usr/bin/env node
|
|
228
228
|
// .husky/pre-push is a link to this file. Build builds each pushed commit in
|
|
229
|
-
// its own snapshot, never the working tree. NODE_ENV is set
|
|
230
|
-
//
|
|
229
|
+
// its own snapshot, never the working tree. NODE_ENV is set for the tools, so a
|
|
230
|
+
// shell that sets another value builds the same.
|
|
231
231
|
import { Build, prePush } from '@zukhruf/git-hooks';
|
|
232
232
|
|
|
233
233
|
await prePush([new Build({ env: { NODE_ENV: 'production' } })]);
|
|
@@ -16,5 +16,12 @@ export declare function updateTargetDefault(nxJson: NxJsonConfiguration, target:
|
|
|
16
16
|
* other keys. A list gets the entries that it does not have.
|
|
17
17
|
*/
|
|
18
18
|
export declare function mergeNxJson(tree: Tree): void;
|
|
19
|
+
/**
|
|
20
|
+
* Every setup runs under production (ADR 0016): the test and serve defaults
|
|
21
|
+
* set NODE_ENV=production, and a NODE_ENV that is there stays. A project
|
|
22
|
+
* target's own env replaces this one, so the web keeps its development and
|
|
23
|
+
* test. init and the node-env-production migration call it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function addProductionNodeEnvDefaults(nxJson: NxJsonConfiguration): void;
|
|
19
26
|
export {};
|
|
20
27
|
//# sourceMappingURL=nx-json.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-json.d.ts","sourceRoot":"","sources":["../../../src/generators/init/nx-json.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,IAAI,EAEV,MAAM,YAAY,CAAC;AA+CpB,eAAO,MAAM,UAAU,GAAI,OAAO,mBAAmB,WACH,CAAC;AAEnD,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,QAAQ,CAAC,EAAE,QAQpC,CAAC;AAEF,KAAK,iBAAiB,GAAG,WAAW,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC,CAAC;AAExE;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,UAAU,EAAE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AE,CAAC,KAAK,EAAE,aAAa,KAAK,aAAa,GAC9C,IAAI,CAON;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAuD5C;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,mBAAmB,GAC1B,IAAI,CAUN"}
|
|
@@ -3,7 +3,7 @@ import { addMissingKeys } from "../add-keys.js";
|
|
|
3
3
|
const namedInputs = {
|
|
4
4
|
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
|
5
5
|
// The hash of a task does not read the environment, so NODE_ENV is an input:
|
|
6
|
-
//
|
|
6
|
+
// a build under another value is never served from the cache.
|
|
7
7
|
production: [
|
|
8
8
|
'default',
|
|
9
9
|
'!{projectRoot}/eslint.config.mjs',
|
|
@@ -119,8 +119,26 @@ export function mergeNxJson(tree) {
|
|
|
119
119
|
continuous: false,
|
|
120
120
|
}));
|
|
121
121
|
}
|
|
122
|
+
addProductionNodeEnvDefaults(nxJson);
|
|
122
123
|
nxJson.sync = { ...nxJson.sync, applyChanges: true };
|
|
123
124
|
return nxJson;
|
|
124
125
|
});
|
|
125
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Every setup runs under production (ADR 0016): the test and serve defaults
|
|
129
|
+
* set NODE_ENV=production, and a NODE_ENV that is there stays. A project
|
|
130
|
+
* target's own env replaces this one, so the web keeps its development and
|
|
131
|
+
* test. init and the node-env-production migration call it.
|
|
132
|
+
*/
|
|
133
|
+
export function addProductionNodeEnvDefaults(nxJson) {
|
|
134
|
+
for (const target of ['test', 'serve']) {
|
|
135
|
+
updateTargetDefault(nxJson, target, (entry) => ({
|
|
136
|
+
...entry,
|
|
137
|
+
options: {
|
|
138
|
+
...entry.options,
|
|
139
|
+
env: addMissingKeys(entry.options?.env, { NODE_ENV: 'production' }),
|
|
140
|
+
},
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
126
144
|
//# sourceMappingURL=nx-json.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-json.js","sourceRoot":"","sources":["../../../src/generators/init/nx-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAMhD,MAAM,WAAW,GAAsC;IACrD,OAAO,EAAE,CAAC,oBAAoB,EAAE,eAAe,CAAC;IAChD,6EAA6E;IAC7E,
|
|
1
|
+
{"version":3,"file":"nx-json.js","sourceRoot":"","sources":["../../../src/generators/init/nx-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAMhD,MAAM,WAAW,GAAsC;IACrD,OAAO,EAAE,CAAC,oBAAoB,EAAE,eAAe,CAAC;IAChD,6EAA6E;IAC7E,8DAA8D;IAC9D,UAAU,EAAE;QACV,SAAS;QACT,kCAAkC;QAClC,uDAAuD;QACvD,mCAAmC;QACnC,mCAAmC;QACnC,EAAE,GAAG,EAAE,UAAU,EAAE;KACpB;IACD,aAAa,EAAE;QACb,mCAAmC;QACnC,oCAAoC;KACrC;CACF,CAAC;AAEF,6EAA6E;AAC7E,gDAAgD;AAChD,MAAM,OAAO,GAA0B;IACrC;QACE,MAAM,EAAE,mBAAmB;QAC3B,OAAO,EAAE;YACP,SAAS,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;YACtC,KAAK,EAAE;gBACL,UAAU,EAAE,OAAO;gBACnB,UAAU,EAAE,mBAAmB;gBAC/B,aAAa,EAAE,YAAY;gBAC3B,aAAa,EAAE,YAAY;aAC5B;SACF;KACF;IACD,EAAE,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;IAChE,kBAAkB;IAClB,oBAAoB;IACpB,kBAAkB;CACnB,CAAC;AAEF,M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,GAAG,KAAK;YACR,OAAO,EAAE;gBACP,GAAG,KAAK,CAAC,OAAO;gBAChB,GAAG,EAAE,cAAc,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;aACpE;SACF,CAAC,CAAC,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export declare function eslintConfig(projectRoot: string, rootOffset: string): string;
|
|
2
|
-
export declare const appTs = "import { evlog } from 'evlog/hono';\nimport { Hono } from 'hono';\nimport { compress } from 'hono/compress';\nimport { contextStorage } from 'hono/context-storage';\nimport { cors } from 'hono/cors';\nimport { HTTPException } from 'hono/http-exception';\nimport { timing } from 'hono/timing';\n\nimport { evlogMiddlewareOptions, evlogRequestContext } from './logging.ts';\n\nconst app = new Hono();\n\napp.use(\n evlog(evlogMiddlewareOptions),\n evlogRequestContext(),\n timing(),\n cors({\n origin: (origin) => {\n
|
|
2
|
+
export declare const appTs = "import { evlog } from 'evlog/hono';\nimport { Hono } from 'hono';\nimport { compress } from 'hono/compress';\nimport { contextStorage } from 'hono/context-storage';\nimport { cors } from 'hono/cors';\nimport { HTTPException } from 'hono/http-exception';\nimport { timing } from 'hono/timing';\n\nimport { evlogMiddlewareOptions, evlogRequestContext } from './logging.ts';\n\nconst app = new Hono();\n\napp.use(\n evlog(evlogMiddlewareOptions),\n evlogRequestContext(),\n timing(),\n // A browser origin gets CORS only when ALLOWED_ORIGINS lists it, in every\n // setup.\n cors({\n origin: (origin) => {\n // A request with no Origin header (a health check, a server call) needs\n // no CORS and never reads ALLOWED_ORIGINS.\n if (!origin) return '';\n const allowed = process.env.ALLOWED_ORIGINS.split(',');\n return allowed.map((entry) => entry.trim()).includes(origin)\n ? origin\n : '';\n },\n credentials: true,\n }),\n // Required by @sdk-it/hono/runtime's `output` helpers.\n contextStorage(),\n);\n\napp.use('/api/*', compress());\n\n// Route modules register on the /api base path. Add new modules to this list;\n// sdk-it only discovers routes that use `validate` and a JSDoc @openapi tag.\nfor await (const route of [import('./routes/healthz.route.ts')]) {\n route.default(app.basePath('/api'));\n}\n\napp.notFound((c) =>\n c.json(\n {\n error: 'Not Found',\n cause: {\n code: 'api/not-found',\n detail: 'The requested resource was not found',\n instance: c.req.path,\n },\n },\n 404,\n ),\n);\n\napp.onError((error, c) => {\n if (error instanceof HTTPException) {\n if (error.status >= 500) {\n c.get('log')?.error(error);\n } else {\n // A bare `status: 400` in telemetry is undiagnosable; keep the cause.\n c.get('log')?.warn(error.message, { cause: error.cause });\n }\n return c.json({ error: error.message, cause: error.cause }, error.status);\n }\n // The log has the error; the response never carries it.\n c.get('log')?.error(error);\n return c.json(\n {\n error: 'Internal Server Error',\n cause: { code: 'api/internal', detail: 'Unexpected error' },\n },\n 500,\n );\n});\n\nexport default app;\n";
|
|
3
3
|
export declare const appTestTs = "import assert from 'node:assert/strict';\nimport { test } from 'node:test';\n\nimport app from './app.ts';\n\ntest('answers the health check on the API base path, with no build sha outside an image', async () => {\n const response = await app.request('/api/healthz');\n\n assert.equal(response.status, 200);\n assert.deepEqual(await response.json(), { status: 'ok', sha: null });\n});\n\ntest('rejects unknown API routes with a JSON cause', async () => {\n const response = await app.request('/api/nope');\n\n assert.equal(response.status, 404);\n const body: unknown = await response.json();\n assert.ok(typeof body === 'object' && body !== null && 'cause' in body);\n});\n";
|
|
4
4
|
export declare function envTs(port: number): string;
|
|
5
5
|
export declare function loggingTs(name: string): string;
|
|
6
6
|
export declare const healthzRouteTs = "import { validate } from '@sdk-it/hono/runtime';\nimport type { Hono } from 'hono';\n\n// sdk-it discovers a route only when: the path is a string literal, an\n// argument is a call literally named `validate` whose selector is an arrow\n// function, the last argument is an arrow function, and the JSDoc block sits\n// directly above the statement.\nexport default function (router: Hono): void {\n /**\n * @openapi getHealthz\n * @tags health\n * @description Report whether the API is up, and the commit it was built from.\n */\n router.get(\n '/healthz',\n validate(() => ({})),\n async (c) => {\n return c.json({ status: 'ok', sha: process.env.BUILD_SHA ?? null });\n },\n );\n}\n";
|
|
7
|
-
export declare const serverTs = "#!/usr/bin/env tsx\n// @nx-target-name: serve\nimport './startup.ts';\n\nimport { createTerminus } from '@godaddy/terminus';\nimport { serve } from '@hono/node-server';\nimport { log } from 'evlog';\n\nimport app from './app.ts';\nimport { flushLogs, logError } from './logging.ts';\n\nconst port = Number.parseInt(process.env.PORT ?? '3000', 10);\n//
|
|
7
|
+
export declare const serverTs = "#!/usr/bin/env tsx\n// @nx-target-name: serve\nimport './startup.ts';\n\nimport { createTerminus } from '@godaddy/terminus';\nimport { serve } from '@hono/node-server';\nimport { log } from 'evlog';\n\nimport app from './app.ts';\nimport { flushLogs, logError } from './logging.ts';\n\nconst port = Number.parseInt(process.env.PORT ?? '3000', 10);\n// HOST is required (env.ts). .env binds 127.0.0.1: the dual-stack wildcard\n// leaves the IPv4 address free for a stray local server to capture proxy\n// traffic. The image binds 0.0.0.0.\nconst hostname = process.env.HOST;\n\nconst server = serve({ fetch: app.fetch, port, hostname }, (info) => {\n log.info({\n event: 'server.started',\n port: info.port,\n address: info.address,\n });\n});\n\n// terminus answers /healthz before Hono sees the request and turns SIGTERM\n// into a drained shutdown.\ncreateTerminus(server, {\n healthChecks: { '/healthz': async () => ({ status: 'ok' }) },\n async onSignal() {\n log.info({ event: 'server.shutdown.started' });\n await flushLogs();\n },\n useExit0: true,\n});\n\nprocess.on('uncaughtException', (error) => {\n logError({ event: 'server.uncaught-exception' }, error);\n process.kill(process.pid, 'SIGTERM');\n});\n\nprocess.on('unhandledRejection', (reason) => {\n logError({ event: 'server.unhandled-rejection' }, reason);\n process.kill(process.pid, 'SIGTERM');\n});\n";
|
|
8
8
|
export declare const startupTs = "import './env.ts';\n\n// Boot module: connect stores, run migrations, and start queues or workers here\n// before the app serves. Empty until the product needs it.\nexport {};\n";
|
|
9
|
-
export declare function envExample(port: number): string;
|
|
9
|
+
export declare function envExample(port: number, name: string): string;
|
|
10
10
|
export interface DockerfileOptions {
|
|
11
11
|
projectRoot: string;
|
|
12
12
|
projectName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/generators/node-app/files.ts"],"names":[],"mappings":"AAGA,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CA2B5E;AAED,eAAO,MAAM,KAAK,
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/generators/node-app/files.ts"],"names":[],"mappings":"AAGA,wBAAgB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CA2B5E;AAED,eAAO,MAAM,KAAK,uuEA8EjB,CAAC;AAEF,eAAO,MAAM,SAAS,8qBAmBrB,CAAC;AAEF,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA6C1C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqH9C;AAED,eAAO,MAAM,cAAc,6sBAqB1B,CAAC;AAEF,eAAO,MAAM,QAAQ,w3CA6CpB,CAAC;AAEF,eAAO,MAAM,SAAS,sLAKrB,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAiB7D;AAED,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,GAAG,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CA6C7D;AAED,eAAO,MAAM,YAAY,gKAYxB,CAAC;AAEF,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAa5E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CA6C3E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAWzD"}
|
|
@@ -44,12 +44,17 @@ app.use(
|
|
|
44
44
|
evlog(evlogMiddlewareOptions),
|
|
45
45
|
evlogRequestContext(),
|
|
46
46
|
timing(),
|
|
47
|
+
// A browser origin gets CORS only when ALLOWED_ORIGINS lists it, in every
|
|
48
|
+
// setup.
|
|
47
49
|
cors({
|
|
48
50
|
origin: (origin) => {
|
|
49
|
-
|
|
51
|
+
// A request with no Origin header (a health check, a server call) needs
|
|
52
|
+
// no CORS and never reads ALLOWED_ORIGINS.
|
|
50
53
|
if (!origin) return '';
|
|
51
|
-
const allowed = process.env.ALLOWED_ORIGINS.split(',')
|
|
52
|
-
return allowed.
|
|
54
|
+
const allowed = process.env.ALLOWED_ORIGINS.split(',');
|
|
55
|
+
return allowed.map((entry) => entry.trim()).includes(origin)
|
|
56
|
+
? origin
|
|
57
|
+
: '';
|
|
53
58
|
},
|
|
54
59
|
credentials: true,
|
|
55
60
|
}),
|
|
@@ -89,17 +94,12 @@ app.onError((error, c) => {
|
|
|
89
94
|
}
|
|
90
95
|
return c.json({ error: error.message, cause: error.cause }, error.status);
|
|
91
96
|
}
|
|
97
|
+
// The log has the error; the response never carries it.
|
|
92
98
|
c.get('log')?.error(error);
|
|
93
99
|
return c.json(
|
|
94
100
|
{
|
|
95
101
|
error: 'Internal Server Error',
|
|
96
|
-
cause: {
|
|
97
|
-
code: 'api/internal',
|
|
98
|
-
detail:
|
|
99
|
-
process.env.NODE_ENV === 'development'
|
|
100
|
-
? String(error)
|
|
101
|
-
: 'Unexpected error',
|
|
102
|
-
},
|
|
102
|
+
cause: { code: 'api/internal', detail: 'Unexpected error' },
|
|
103
103
|
},
|
|
104
104
|
500,
|
|
105
105
|
);
|
|
@@ -133,11 +133,9 @@ export function envTs(port) {
|
|
|
133
133
|
import { logError } from './logging.ts';
|
|
134
134
|
|
|
135
135
|
const env = z.object({
|
|
136
|
-
NODE_ENV: z
|
|
137
|
-
.enum(['development', 'test', 'production'])
|
|
138
|
-
.default('development'),
|
|
139
136
|
PORT: z.string().optional().default('${port}'),
|
|
140
|
-
|
|
137
|
+
// The bind address: 127.0.0.1 in .env, 0.0.0.0 in the image.
|
|
138
|
+
HOST: z.string().min(1),
|
|
141
139
|
// Kept a string: process.env stays string-valued so the ProcessEnv
|
|
142
140
|
// augmentation below remains compatible with every Node API typed against
|
|
143
141
|
// it (child_process env, etc.). Parse lists at the use site.
|
|
@@ -146,6 +144,10 @@ const env = z.object({
|
|
|
146
144
|
// Dockerfile). /api/healthz reports it, so a deploy can tell the new
|
|
147
145
|
// container from the old one. A process that is not an image has none.
|
|
148
146
|
BUILD_SHA: z.string().min(1).optional(),
|
|
147
|
+
// logging.ts reads these two before this check runs. The folder of the log
|
|
148
|
+
// files (unset: no file), and \`true\` for readable logs (unset: JSON lines).
|
|
149
|
+
LOG_DIR: z.string().min(1).optional(),
|
|
150
|
+
LOG_PRETTY: z.enum(['true', 'false']).optional(),
|
|
149
151
|
});
|
|
150
152
|
|
|
151
153
|
const parsed = env.safeParse(process.env);
|
|
@@ -198,18 +200,19 @@ declare module 'hono' {
|
|
|
198
200
|
}
|
|
199
201
|
|
|
200
202
|
// This module is imported by env.ts (to report validation failures), so it
|
|
201
|
-
// runs before the environment is validated and reads the raw
|
|
202
|
-
|
|
203
|
+
// runs before the environment is validated and reads the raw variables. The
|
|
204
|
+
// log files go to LOG_DIR when it is set.
|
|
205
|
+
const logDir = process.env.LOG_DIR;
|
|
203
206
|
const fileDrain =
|
|
204
|
-
|
|
205
|
-
?
|
|
207
|
+
logDir === undefined
|
|
208
|
+
? undefined
|
|
209
|
+
: createDrainPipeline<DrainContext>({ batch: { size: 1 } })(
|
|
206
210
|
createFsDrain({
|
|
207
|
-
dir:
|
|
211
|
+
dir: logDir,
|
|
208
212
|
maxFiles: 7,
|
|
209
213
|
maxSizePerFile: 10 * 1024 * 1024,
|
|
210
214
|
}),
|
|
211
|
-
)
|
|
212
|
-
: undefined;
|
|
215
|
+
);
|
|
213
216
|
|
|
214
217
|
// evlog derives no level from the response status, so a handler that
|
|
215
218
|
// *returns* a 5xx (rather than throwing) would log at info. Enrichment runs
|
|
@@ -222,7 +225,8 @@ function promoteServerErrors(context: EnrichContext): void {
|
|
|
222
225
|
|
|
223
226
|
const config = defineEvlog({
|
|
224
227
|
service: '${name}',
|
|
225
|
-
|
|
228
|
+
// Readable logs when LOG_PRETTY is true, JSON lines otherwise.
|
|
229
|
+
pretty: process.env.LOG_PRETTY === 'true',
|
|
226
230
|
redact: {
|
|
227
231
|
paths: [
|
|
228
232
|
'authorization',
|
|
@@ -321,11 +325,10 @@ import app from './app.ts';
|
|
|
321
325
|
import { flushLogs, logError } from './logging.ts';
|
|
322
326
|
|
|
323
327
|
const port = Number.parseInt(process.env.PORT ?? '3000', 10);
|
|
324
|
-
//
|
|
325
|
-
// the IPv4 address free for a stray local server to capture proxy
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
(process.env.NODE_ENV === 'development' ? '127.0.0.1' : undefined);
|
|
328
|
+
// HOST is required (env.ts). .env binds 127.0.0.1: the dual-stack wildcard
|
|
329
|
+
// leaves the IPv4 address free for a stray local server to capture proxy
|
|
330
|
+
// traffic. The image binds 0.0.0.0.
|
|
331
|
+
const hostname = process.env.HOST;
|
|
329
332
|
|
|
330
333
|
const server = serve({ fetch: app.fetch, port, hostname }, (info) => {
|
|
331
334
|
log.info({
|
|
@@ -362,17 +365,22 @@ export const startupTs = `import './env.ts';
|
|
|
362
365
|
// before the app serves. Empty until the product needs it.
|
|
363
366
|
export {};
|
|
364
367
|
`;
|
|
365
|
-
export function envExample(port) {
|
|
368
|
+
export function envExample(port, name) {
|
|
366
369
|
return `# Copy to \`.env\` (gitignored). Nx loads this project's \`.env\`, \`.env.<target>\`
|
|
367
370
|
# and \`.env.<target>.<configuration>\` into every task it runs here, so
|
|
368
|
-
# \`nx run <project>:serve\` needs no dotenv.
|
|
369
|
-
#
|
|
371
|
+
# \`nx run <project>:serve\` needs no dotenv.
|
|
372
|
+
# Every setup runs under production; no code reads NODE_ENV (ADR 0016).
|
|
373
|
+
NODE_ENV=production
|
|
370
374
|
PORT=${port}
|
|
371
|
-
# Bind address.
|
|
372
|
-
#
|
|
375
|
+
# Bind address, required. 127.0.0.1, so portless and the web dev proxy always
|
|
376
|
+
# reach the server; the image binds 0.0.0.0.
|
|
373
377
|
HOST=127.0.0.1
|
|
374
|
-
# Comma-separated browser origins allowed
|
|
378
|
+
# Comma-separated browser origins allowed to call the API (CORS).
|
|
375
379
|
ALLOWED_ORIGINS=
|
|
380
|
+
# The folder of the log files. Unset writes no log file.
|
|
381
|
+
LOG_DIR=.evlog/logs/${name}
|
|
382
|
+
# true prints readable logs; unset prints JSON lines.
|
|
383
|
+
LOG_PRETTY=true
|
|
376
384
|
`;
|
|
377
385
|
}
|
|
378
386
|
export function dockerfile(options) {
|
|
@@ -381,6 +389,8 @@ export function dockerfile(options) {
|
|
|
381
389
|
const spaCopy = spa
|
|
382
390
|
? `COPY --from=build /workspace/${spa.projectRoot}/dist ./${spa.projectRoot}/dist\n`
|
|
383
391
|
: '';
|
|
392
|
+
// The backend serves the web build that UI_ROOT names (pair).
|
|
393
|
+
const uiRoot = spa ? ` UI_ROOT=/app/${spa.projectRoot}/dist` : '';
|
|
384
394
|
return `# syntax=docker/dockerfile:1
|
|
385
395
|
# @zukhruf/nx:node-app writes this file, and @zukhruf/nx:pair writes it again.
|
|
386
396
|
# Build from the workspace root: \`nx run ${projectName}:docker:build\`.
|
|
@@ -403,7 +413,7 @@ FROM node:lts-alpine AS runtime
|
|
|
403
413
|
# The commit this image is built from; /api/healthz reports it. docker:build
|
|
404
414
|
# passes it, and an image built without it does not start (env.ts).
|
|
405
415
|
ARG BUILD_SHA
|
|
406
|
-
ENV NODE_ENV=production HOST=0.0.0.0 PORT=${port} BUILD_SHA=$BUILD_SHA
|
|
416
|
+
ENV NODE_ENV=production HOST=0.0.0.0 PORT=${port} BUILD_SHA=$BUILD_SHA${uiRoot}
|
|
407
417
|
RUN npm install -g npm@latest
|
|
408
418
|
WORKDIR /app
|
|
409
419
|
# prune-lockfile writes the runtime manifest (type: module, runtime deps only)
|
|
@@ -482,7 +492,10 @@ export function clientManifest(name, apiProjectName) {
|
|
|
482
492
|
sdk: {
|
|
483
493
|
// Config discovery walks up from cwd to the api's sdk-it.config.ts.
|
|
484
494
|
command: 'sdk-it generate',
|
|
485
|
-
options: {
|
|
495
|
+
options: {
|
|
496
|
+
cwd: '{projectRoot}',
|
|
497
|
+
env: { NODE_ENV: 'production' },
|
|
498
|
+
},
|
|
486
499
|
cache: true,
|
|
487
500
|
inputs: [
|
|
488
501
|
{ projects: [apiProjectName], input: 'production' },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/generators/node-app/files.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+EAA+E;AAE/E,MAAM,UAAU,YAAY,CAAC,WAAmB,EAAE,UAAkB;IAClE,OAAO;;qDAE4C,UAAU;;;;;;;;;;;;;;;;;mCAiB5B,WAAW;;;;;;CAM7C,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8EpB,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;CAmBxB,CAAC;AAEF,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,OAAO
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/generators/node-app/files.ts"],"names":[],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O,EAAE,iBAAiB;aAC3B;SACF;QACD,YAAY,EAAE,EAAE,yBAAyB,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE;QACpE,EAAE,EAAE;YACF,WAAW,EAAE,SAAS;YACtB,OAAO,EAAE;gBACP,GAAG,EAAE;oBACH,oEAAoE;oBACpE,OAAO,EAAE,iBAAiB;oBAC1B,OAAO,EAAE;wBACP,GAAG,EAAE,eAAe;wBACpB,GAAG,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE;qBAChC;oBACD,KAAK,EAAE,IAAI;oBACX,MAAM,EAAE;wBACN,EAAE,QAAQ,EAAE,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE;wBACnD,mCAAmC;wBACnC,4BAA4B;qBAC7B;oBACD,OAAO,EAAE;wBACP,mBAAmB;wBACnB,oBAAoB;wBACpB,6BAA6B;qBAC9B;iBACF;aACF;SACF;KACF,CAAC;IACF,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,UAAkB;IAC/C,MAAM,QAAQ,GAAG;QACf,OAAO,EAAE,MAAM,UAAU,oBAAoB;QAC7C,eAAe,EAAE;YACf,MAAM,EAAE,SAAS;YACjB,eAAe,EAAE,8BAA8B;SAChD;QACD,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,EAAE;KACZ,CAAC;IACF,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AAClD,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { formatFiles, installPackagesTask, runTasksInSerial, updateJson, writeJson, } from '@nx/devkit';
|
|
2
|
-
import { addMissingKeys } from "../add-keys.js";
|
|
3
2
|
import { addLines } from "../add-lines.js";
|
|
4
3
|
import { appDirectory, projectNameOf } from "../app-directory.js";
|
|
5
4
|
import initGenerator from "../init/generator.js";
|
|
6
5
|
import { mergeGeneratorDefaults, unique, updateTargetDefault, } from "../init/nx-json.js";
|
|
7
6
|
import { nxPlugin } from "../nx-plugin.js";
|
|
7
|
+
import { addPortlessProxyEnv } from "../portless-env.js";
|
|
8
8
|
import { fseventsScript, rootDependencyNames, settleRootDependencies, } from "../root-dependencies.js";
|
|
9
9
|
import { appPackageVersions as versions } from "../versions.js";
|
|
10
10
|
import { workspaceScope } from "../workspace-scope.js";
|
|
@@ -67,9 +67,9 @@ export default async function nodeAppGenerator(tree, options) {
|
|
|
67
67
|
tree.write(`${projectRoot}/src/server.ts`, serverTs);
|
|
68
68
|
tree.write(`${projectRoot}/src/startup.ts`, startupTs);
|
|
69
69
|
// .env.example is the generator's; .env is the developer's copy.
|
|
70
|
-
tree.write(`${projectRoot}/.env.example`, envExample(port));
|
|
70
|
+
tree.write(`${projectRoot}/.env.example`, envExample(port, name));
|
|
71
71
|
if (!tree.exists(`${projectRoot}/.env`)) {
|
|
72
|
-
tree.write(`${projectRoot}/.env`, envExample(port));
|
|
72
|
+
tree.write(`${projectRoot}/.env`, envExample(port, name));
|
|
73
73
|
}
|
|
74
74
|
wireSdk(tree, { projectRoot, name, projectName, rootOffset, scope });
|
|
75
75
|
tree.write(`${projectRoot}/Dockerfile`, dockerfile({ projectRoot, projectName, port }));
|
|
@@ -189,11 +189,11 @@ function writeProjectPackageJson(tree, app) {
|
|
|
189
189
|
build: buildTarget(app.projectRoot),
|
|
190
190
|
// @nx/js/tsx infers the command from the header of src/server.ts.
|
|
191
191
|
// @nx/node writes serve as continuous, and a project value wins
|
|
192
|
-
// over the discrete target default.
|
|
193
|
-
//
|
|
192
|
+
// over the discrete target default. NODE_ENV is production, as in
|
|
193
|
+
// every setup; the app reads its own settings from its .env.
|
|
194
194
|
serve: {
|
|
195
195
|
dependsOn: ['^build'],
|
|
196
|
-
options: { env: { NODE_ENV: '
|
|
196
|
+
options: { env: { NODE_ENV: 'production' } },
|
|
197
197
|
},
|
|
198
198
|
portless: {
|
|
199
199
|
command: `portless --name ${app.name}.${app.scope} --app-port ${app.port} -- nx run ${app.projectName}:serve --output-style=stream-without-prefixes`,
|
|
@@ -300,23 +300,7 @@ function mergeNodeNxJson(tree) {
|
|
|
300
300
|
dependsOn: unique([...inferred, ...(entry.dependsOn ?? []), '^sdk']),
|
|
301
301
|
}));
|
|
302
302
|
}
|
|
303
|
-
|
|
304
|
-
// starts it sets its mode. PORTLESS_UNPRIVILEGED starts it without sudo,
|
|
305
|
-
// so an agent with no TTY can. PORTLESS_HTTPS keeps it on HTTPS: a
|
|
306
|
-
// stopped unprivileged proxy otherwise restarts on plain HTTP, and the
|
|
307
|
-
// portless origin in ALLOWED_ORIGINS and the HMR of the web are https. No
|
|
308
|
-
// PORTLESS_TLD: localhost is the default, and a set TLD replaces the TLDs
|
|
309
|
-
// that another repo's proxy saved. Copy in react-app (docs/copied-code.md).
|
|
310
|
-
updateTargetDefault(nxJson, 'portless', (entry) => ({
|
|
311
|
-
...entry,
|
|
312
|
-
options: {
|
|
313
|
-
...entry.options,
|
|
314
|
-
env: addMissingKeys(entry.options?.env, {
|
|
315
|
-
PORTLESS_UNPRIVILEGED: '1',
|
|
316
|
-
PORTLESS_HTTPS: '1',
|
|
317
|
-
}),
|
|
318
|
-
},
|
|
319
|
-
}));
|
|
303
|
+
addPortlessProxyEnv(nxJson);
|
|
320
304
|
// sdk-it.config.ts imports the root CLI. Outside production, its closure
|
|
321
305
|
// stays out of the pruned runtime lockfile of the app.
|
|
322
306
|
nxJson.namedInputs ??= {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/generators/node-app/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,
|
|
1
|
+
{"version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,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
export declare function apiTs(clientName: string): string;
|
|
2
|
-
/**
|
|
3
|
-
export declare
|
|
2
|
+
/** The first line of the UI mount in app.ts; auth inserts its routes above it. */
|
|
3
|
+
export declare const uiMountComment = "// pair: the backend serves the web build that UI_ROOT names.";
|
|
4
|
+
/** The import of the UI route, in the mount of each version of pair. */
|
|
5
|
+
export declare const uiRouteImport = "import('./routes/ui.route.ts')";
|
|
6
|
+
/** The lines of app.ts that mount the UI route of pair. */
|
|
7
|
+
export declare const uiMount = "// pair: the backend serves the web build that UI_ROOT names. Unset, as in\n// development, where Vite serves the web, there is no UI route.\nconst uiRoot = process.env.UI_ROOT;\nif (uiRoot !== undefined) {\n await (await import('./routes/ui.route.ts')).default(app, uiRoot);\n}";
|
|
8
|
+
/** The mount that pair wrote before UI_ROOT; a second run replaces it. */
|
|
9
|
+
export declare const legacyUiMount = "// pair fixed the path of the web build; development enters through the Vite proxy.\n(await import('./routes/ui.route.ts')).default(app);";
|
|
10
|
+
/** The line of env.ts that declares UI_ROOT. */
|
|
11
|
+
export declare const uiRootEnvTs = " // The folder of the web build that the backend serves (ui.route.ts). Unset,\n // the backend serves no UI.\n UI_ROOT: z.string().min(1).optional(),\n";
|
|
12
|
+
export declare const uiRouteTs = "import { readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\n\nimport { serveStatic } from '@hono/node-server/serve-static';\nimport type { Hono } from 'hono';\nimport { compress } from 'hono/compress';\nimport { etag } from 'hono/etag';\n\nimport { logError } from '../logging.ts';\n\n// Same-origin SPA shell from the web build in `root` (UI_ROOT): hashed\n// assets are immutable (served precompressed when the web build emitted\n// .br/.gz), and every other GET returns index.html so the client router owns\n// the URL. A GET under /api/ goes on to the API routes and their notFound.\n// It reads index.html once, at startup, and the process stops there when\n// UI_ROOT names no web build.\nexport default async function (router: Hono, root: string): Promise<void> {\n const indexHtml = join(root, 'index.html');\n const html = await readIndexHtml(indexHtml);\n router.use(\n '/assets/*',\n serveStatic({\n root,\n precompressed: true,\n onFound: (_path, c) => {\n c.header('Cache-Control', 'public, max-age=31536000, immutable');\n },\n }),\n );\n router.get('*', compress(), etag(), async (c, next) => {\n if (c.req.path.startsWith('/api/')) {\n await next();\n return;\n }\n return c.html(html);\n });\n}\n\nasync function readIndexHtml(path: string): Promise<string> {\n try {\n return await readFile(path, 'utf-8');\n } catch (error) {\n if (!(Error.isError(error) && 'code' in error && error.code === 'ENOENT')) {\n throw error;\n }\n logError(\n {\n event: 'ui.build.missing',\n message: `UI_ROOT names no web build: ${path} does not exist. Build the web app, or unset UI_ROOT.`,\n },\n error,\n );\n process.exit(1);\n }\n}\n";
|
|
4
13
|
//# sourceMappingURL=files.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/generators/pair/files.ts"],"names":[],"mappings":"AAGA,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAWhD;AAED,
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/generators/pair/files.ts"],"names":[],"mappings":"AAGA,wBAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAWhD;AAED,kFAAkF;AAClF,eAAO,MAAM,cAAc,kEACsC,CAAC;AAElE,wEAAwE;AACxE,eAAO,MAAM,aAAa,mCAAmC,CAAC;AAE9D,2DAA2D;AAC3D,eAAO,MAAM,OAAO,4RAKlB,CAAC;AAEH,0EAA0E;AAC1E,eAAO,MAAM,aAAa,8IACa,CAAC;AAExC,gDAAgD;AAChD,eAAO,MAAM,WAAW,+JAGvB,CAAC;AAEF,eAAO,MAAM,SAAS,mvDAuDrB,CAAC"}
|
|
@@ -12,32 +12,48 @@ export const api = new Client({
|
|
|
12
12
|
});
|
|
13
13
|
`;
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
/** The first line of the UI mount in app.ts; auth inserts its routes above it. */
|
|
16
|
+
export const uiMountComment = '// pair: the backend serves the web build that UI_ROOT names.';
|
|
17
|
+
/** The import of the UI route, in the mount of each version of pair. */
|
|
18
|
+
export const uiRouteImport = "import('./routes/ui.route.ts')";
|
|
19
|
+
/** The lines of app.ts that mount the UI route of pair. */
|
|
20
|
+
export const uiMount = `${uiMountComment} Unset, as in
|
|
21
|
+
// development, where Vite serves the web, there is no UI route.
|
|
22
|
+
const uiRoot = process.env.UI_ROOT;
|
|
23
|
+
if (uiRoot !== undefined) {
|
|
24
|
+
await (await ${uiRouteImport}).default(app, uiRoot);
|
|
25
|
+
}`;
|
|
26
|
+
/** The mount that pair wrote before UI_ROOT; a second run replaces it. */
|
|
27
|
+
export const legacyUiMount = `// pair fixed the path of the web build; development enters through the Vite proxy.
|
|
28
|
+
(await ${uiRouteImport}).default(app);`;
|
|
29
|
+
/** The line of env.ts that declares UI_ROOT. */
|
|
30
|
+
export const uiRootEnvTs = ` // The folder of the web build that the backend serves (ui.route.ts). Unset,
|
|
31
|
+
// the backend serves no UI.
|
|
32
|
+
UI_ROOT: z.string().min(1).optional(),
|
|
33
|
+
`;
|
|
34
|
+
export const uiRouteTs = `import { readFile } from 'node:fs/promises';
|
|
35
|
+
import { join } from 'node:path';
|
|
19
36
|
|
|
20
37
|
import { serveStatic } from '@hono/node-server/serve-static';
|
|
21
38
|
import type { Hono } from 'hono';
|
|
22
39
|
import { compress } from 'hono/compress';
|
|
23
40
|
import { etag } from 'hono/etag';
|
|
24
41
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
);
|
|
36
|
-
const indexHtml = join(webDist, 'index.html');
|
|
42
|
+
import { logError } from '../logging.ts';
|
|
43
|
+
|
|
44
|
+
// Same-origin SPA shell from the web build in \`root\` (UI_ROOT): hashed
|
|
45
|
+
// assets are immutable (served precompressed when the web build emitted
|
|
46
|
+
// .br/.gz), and every other GET returns index.html so the client router owns
|
|
47
|
+
// the URL. A GET under /api/ goes on to the API routes and their notFound.
|
|
48
|
+
// It reads index.html once, at startup, and the process stops there when
|
|
49
|
+
// UI_ROOT names no web build.
|
|
50
|
+
export default async function (router: Hono, root: string): Promise<void> {
|
|
51
|
+
const indexHtml = join(root, 'index.html');
|
|
52
|
+
const html = await readIndexHtml(indexHtml);
|
|
37
53
|
router.use(
|
|
38
54
|
'/assets/*',
|
|
39
55
|
serveStatic({
|
|
40
|
-
root
|
|
56
|
+
root,
|
|
41
57
|
precompressed: true,
|
|
42
58
|
onFound: (_path, c) => {
|
|
43
59
|
c.header('Cache-Control', 'public, max-age=31536000, immutable');
|
|
@@ -49,25 +65,26 @@ export default function (router: Hono): void {
|
|
|
49
65
|
await next();
|
|
50
66
|
return;
|
|
51
67
|
}
|
|
52
|
-
const html = await readFile(indexHtml, 'utf-8').catch(() => undefined);
|
|
53
|
-
if (html === undefined) {
|
|
54
|
-
return c.json(
|
|
55
|
-
{
|
|
56
|
-
error: 'Not Found',
|
|
57
|
-
cause: {
|
|
58
|
-
code: 'ui/build-missing',
|
|
59
|
-
detail:
|
|
60
|
-
process.env.NODE_ENV === 'development'
|
|
61
|
-
? \`Build the web app first (expected \${indexHtml})\`
|
|
62
|
-
: 'The web build is not available',
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
404,
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
68
|
return c.html(html);
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
|
|
72
|
+
async function readIndexHtml(path: string): Promise<string> {
|
|
73
|
+
try {
|
|
74
|
+
return await readFile(path, 'utf-8');
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (!(Error.isError(error) && 'code' in error && error.code === 'ENOENT')) {
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
logError(
|
|
80
|
+
{
|
|
81
|
+
event: 'ui.build.missing',
|
|
82
|
+
message: \`UI_ROOT names no web build: \${path} does not exist. Build the web app, or unset UI_ROOT.\`,
|
|
83
|
+
},
|
|
84
|
+
error,
|
|
85
|
+
);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
72
88
|
}
|
|
89
|
+
`;
|
|
73
90
|
//# sourceMappingURL=files.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/generators/pair/files.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,+DAA+D;AAE/D,MAAM,UAAU,KAAK,CAAC,UAAkB;IACtC,OAAO,2BAA2B,UAAU;;;;;;;;;CAS7C,CAAC;AACF,CAAC;AAED,
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/generators/pair/files.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,+DAA+D;AAE/D,MAAM,UAAU,KAAK,CAAC,UAAkB;IACtC,OAAO,2BAA2B,UAAU;;;;;;;;;CAS7C,CAAC;AACF,CAAC;AAED,kFAAkF;AAClF,MAAM,CAAC,MAAM,cAAc,GACzB,+DAA+D,CAAC;AAElE,wEAAwE;AACxE,MAAM,CAAC,MAAM,aAAa,GAAG,gCAAgC,CAAC;AAE9D,2DAA2D;AAC3D,MAAM,CAAC,MAAM,OAAO,GAAG,GAAG,cAAc;;;;iBAIvB,aAAa;EAC5B,CAAC;AAEH,0EAA0E;AAC1E,MAAM,CAAC,MAAM,aAAa,GAAG;SACpB,aAAa,iBAAiB,CAAC;AAExC,gDAAgD;AAChD,MAAM,CAAC,MAAM,WAAW,GAAG;;;CAG1B,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/pair/generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/pair/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,EAAqC,MAAM,YAAY,CAAC;AAc1E,MAAM,WAAW,WAAW;IAC1B,kEAAkE;IAClE,GAAG,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,GAAG,EAAE,MAAM,CAAC;CACb;AAED,yFAAyF;AACzF,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAI1D;AAmCD;;;;;;;GAOG;AACH,wBAA8B,aAAa,CACzC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,IAAI,CAAC,CAgDf"}
|