@stacksjs/buddy 0.70.223 → 0.70.225
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/dist/commands/serve.d.ts +1 -0
- package/dist/commands/serve.js +70 -69
- package/dist/serve-entry.js +2 -6
- package/package.json +1 -1
package/dist/commands/serve.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export declare function resolveUserPartialsPath(cwd?: unknown, configuredDir?: s
|
|
|
19
19
|
* it {@link resolveUserPartialsPath} falls back to the conventions.
|
|
20
20
|
*/
|
|
21
21
|
export declare function loadStxPartialsDir(cwd?: unknown): Promise<string | undefined>;
|
|
22
|
+
export declare function startProductionServer(options?: { port?: string | number, verbose?: boolean }): Promise<void>;
|
|
22
23
|
export declare function serve(buddy: CLI): void;
|
|
23
24
|
/**
|
|
24
25
|
* `buddy serve:api` — boot the production API server (bun-router routes).
|
package/dist/commands/serve.js
CHANGED
|
@@ -90,80 +90,81 @@ function resolveCsrfMiddlewarePath() {
|
|
|
90
90
|
return vendored;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
export function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (isApiBoundRequest(req, url.pathname))
|
|
138
|
-
try {
|
|
139
|
-
return await proxyToBackend(req, apiBase);
|
|
140
|
-
} catch (error) {
|
|
141
|
-
log.error(`API proxy to ${apiBase} failed: ${error.message}`);
|
|
142
|
-
return new Response("Bad Gateway", { status: 502 });
|
|
143
|
-
}
|
|
144
|
-
if (existsSync(join(process.cwd(), "resources/views/blog.stx"))) {
|
|
145
|
-
const { renderBlogFeed } = await import("@stacksjs/actions/blog"), feed = await renderBlogFeed(req);
|
|
146
|
-
if (feed)
|
|
147
|
-
return feed;
|
|
148
|
-
}
|
|
149
|
-
globalThis.__stxServeSearch = url.search;
|
|
150
|
-
globalThis.__stxServeCookies = parseCookies(req);
|
|
151
|
-
return;
|
|
152
|
-
},
|
|
153
|
-
onResponse: async (req, response) => {
|
|
154
|
-
const method = req.method.toUpperCase();
|
|
155
|
-
if (method !== "GET" && method !== "HEAD")
|
|
156
|
-
return;
|
|
93
|
+
export async function startProductionServer(options) {
|
|
94
|
+
if (options?.port)
|
|
95
|
+
process.env.PORT = String(options.port);
|
|
96
|
+
process.env.APP_ENV = process.env.APP_ENV || "production";
|
|
97
|
+
const port = Number(process.env.PORT) || 3000, { config, overridesReady } = await import("@stacksjs/config");
|
|
98
|
+
await overridesReady;
|
|
99
|
+
const { injectGlobalAutoImports } = await import("@stacksjs/server");
|
|
100
|
+
await injectGlobalAutoImports();
|
|
101
|
+
let stxServe;
|
|
102
|
+
const serveCandidates = [
|
|
103
|
+
join(homedir(), "Code/Tools/stx/packages/bun-plugin/dist/serve.js"),
|
|
104
|
+
join(process.cwd(), "pantry/bun-plugin-stx/dist/serve.js")
|
|
105
|
+
];
|
|
106
|
+
for (const entry of serveCandidates)
|
|
107
|
+
try {
|
|
108
|
+
if (existsSync(entry)) {
|
|
109
|
+
({ serve: stxServe } = await import(entry));
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
} catch {}
|
|
113
|
+
if (!stxServe)
|
|
114
|
+
({ serve: stxServe } = await import("bun-plugin-stx/serve"));
|
|
115
|
+
const stxModule = await resolveVendoredStxModule(), { site: siteConfig, i18n: i18nConfig } = await loadStxSiteConfig(), userViewsPath = "resources/views", defaultsResources = resolveDefaultsResources(), defaultViewsPath = join(defaultsResources, "views"), userLayoutsPath = existsSync("resources/views/layouts") ? "resources/views/layouts" : "resources/layouts", userPartialsPath = resolveUserPartialsPath(process.cwd(), await loadStxPartialsDir()), apiBase = process.env.API_URL || `http://127.0.0.1:${Number(process.env.PORT_API) || config.ports?.api || 3008}`;
|
|
116
|
+
log.info(`Starting production server on port ${port}...`);
|
|
117
|
+
await stxServe({
|
|
118
|
+
patterns: [userViewsPath, defaultViewsPath],
|
|
119
|
+
port,
|
|
120
|
+
autoIncrementPort: !1,
|
|
121
|
+
reusePort: ["production", "staging", "development"].includes((process.env.APP_ENV || "").toLowerCase()),
|
|
122
|
+
componentsDir: join(defaultsResources, "components"),
|
|
123
|
+
layoutsDir: userLayoutsPath,
|
|
124
|
+
...userPartialsPath && { partialsDir: userPartialsPath },
|
|
125
|
+
fallbackLayoutsDir: join(defaultsResources, "layouts"),
|
|
126
|
+
fallbackPartialsDir: defaultViewsPath,
|
|
127
|
+
quiet: options?.verbose !== !0,
|
|
128
|
+
...stxModule && { stxModule },
|
|
129
|
+
...i18nConfig && { i18n: i18nConfig },
|
|
130
|
+
...siteConfig?.url && { site: siteConfig },
|
|
131
|
+
onRequest: async (req) => {
|
|
132
|
+
const { maintenanceGate, isApiBoundRequest, proxyToBackend } = await import("@stacksjs/server"), gated = await maintenanceGate(req);
|
|
133
|
+
if (gated)
|
|
134
|
+
return gated;
|
|
135
|
+
const url = new URL(req.url);
|
|
136
|
+
if (isApiBoundRequest(req, url.pathname))
|
|
157
137
|
try {
|
|
158
|
-
|
|
159
|
-
return seedCsrfCookieIfMissing(req, response);
|
|
138
|
+
return await proxyToBackend(req, apiBase);
|
|
160
139
|
} catch (error) {
|
|
161
|
-
log.
|
|
140
|
+
log.error(`API proxy to ${apiBase} failed: ${error.message}`);
|
|
141
|
+
return new Response("Bad Gateway", { status: 502 });
|
|
162
142
|
}
|
|
143
|
+
if (existsSync(join(process.cwd(), "resources/views/blog.stx"))) {
|
|
144
|
+
const { renderBlogFeed } = await import("@stacksjs/actions/blog"), feed = await renderBlogFeed(req);
|
|
145
|
+
if (feed)
|
|
146
|
+
return feed;
|
|
163
147
|
}
|
|
164
|
-
|
|
165
|
-
|
|
148
|
+
globalThis.__stxServeSearch = url.search;
|
|
149
|
+
globalThis.__stxServeCookies = parseCookies(req);
|
|
150
|
+
return;
|
|
151
|
+
},
|
|
152
|
+
onResponse: async (req, response) => {
|
|
153
|
+
const method = req.method.toUpperCase();
|
|
154
|
+
if (method !== "GET" && method !== "HEAD")
|
|
155
|
+
return;
|
|
156
|
+
try {
|
|
157
|
+
const { seedCsrfCookieIfMissing } = await import(resolveCsrfMiddlewarePath());
|
|
158
|
+
return seedCsrfCookieIfMissing(req, response);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
log.debug(`CSRF cookie seeding skipped: ${error.message}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
166
163
|
});
|
|
164
|
+
log.success(`Production server listening on http://0.0.0.0:${port}`);
|
|
165
|
+
}
|
|
166
|
+
export function serve(buddy) {
|
|
167
|
+
buddy.command("serve", "Start the production HTTP server (STX views + /api proxy + coming-soon/maintenance gate)").option("-p, --port <port>", "Port to listen on (defaults to PORT env or 3000)").option("--verbose", "Enable verbose output", { default: !1 }).action(startProductionServer);
|
|
167
168
|
}
|
|
168
169
|
export function serveApi(buddy) {
|
|
169
170
|
buddy.command("serve:api", "Start the production API server (bun-router routes the frontend proxies /api to)").option("-p, --port <port>", "Port to listen on (defaults to PORT env or 3008)").action(async (options) => {
|
package/dist/serve-entry.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import process from "node:process";
|
|
2
|
-
import {
|
|
3
|
-
import { serve } from "./commands/serve";
|
|
2
|
+
import { startProductionServer } from "./commands/serve";
|
|
4
3
|
process.env.APP_ENV ||= "production";
|
|
5
4
|
process.env.NODE_ENV ||= "production";
|
|
6
|
-
|
|
7
|
-
serve(buddy);
|
|
8
|
-
process.argv.splice(2, 0, "serve");
|
|
9
|
-
await buddy.parse();
|
|
5
|
+
await startProductionServer();
|