@plitzi/sdk-server 0.39.4 → 0.39.6
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/CHANGELOG.md +21 -0
- package/README.md +1 -1
- package/dist/adapters/cloudAdapters.d.ts +7 -0
- package/dist/adapters/space/index.d.ts +2 -0
- package/dist/adapters/space/resolvers.d.ts +14 -3
- package/dist/adapters/space/snapshotPreview.d.ts +45 -0
- package/dist/adapters/space/types.d.ts +4 -1
- package/dist/cache.js +1 -1
- package/dist/chunks/{buildBody-BSC0UbjP.js → buildBody-Bm398uxH.js} +600 -63
- package/dist/chunks/{core-w7FIMpgv.js → core-CoKORAOg.js} +149 -23
- package/dist/chunks/{createServer-BQ0KE0Qu.js → createServer-BSmQqzwb.js} +31 -607
- package/dist/chunks/{platform-C0AVlwpB.js → platform-BTssQQXp.js} +1 -1
- package/dist/chunks/sdkAssets-CXGoc_WE.js +60 -0
- package/dist/chunks/{token-CBUubxtm.js → token-XEz1n4jp.js} +1 -1
- package/dist/chunks/views/template.ejs +5 -0
- package/dist/core/services/robotsTxt.d.ts +3 -1
- package/dist/deploy/aws/s3.d.ts +51 -0
- package/dist/deploy/aws/sigv4.d.ts +33 -0
- package/dist/deploy/contentType.d.ts +2 -0
- package/dist/deploy/fingerprint.d.ts +18 -0
- package/dist/deploy/folder.d.ts +6 -0
- package/dist/deploy/ftp.d.ts +27 -0
- package/dist/deploy/sdkFiles.d.ts +11 -0
- package/dist/deploy/spaShell.d.ts +35 -0
- package/dist/deploy/staticSite.d.ts +44 -0
- package/dist/deploy/types.d.ts +58 -0
- package/dist/deploy/zip.d.ts +8 -0
- package/dist/deploy.d.ts +24 -0
- package/dist/deploy.js +938 -0
- package/dist/handlers.js +1 -1
- package/dist/helpers/ownVersion.d.ts +1 -0
- package/dist/index.js +3 -3
- package/dist/oauth.js +1 -1
- package/dist/platform.js +1 -1
- package/dist/project.js +3 -3
- package/dist/spaces.d.ts +2 -2
- package/dist/spaces.js +1 -1
- package/dist/ssr.d.ts +1 -1
- package/dist/ssr.js +1 -1
- package/package.json +15 -13
- package/skills/plitzi-authoring/reference/authoring-errors.md +8 -4
- package/skills/plitzi-authoring/reference/efficiency.md +2 -1
- package/skills/plitzi-authoring/reference/layouts.md +2 -1
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $ as
|
|
1
|
+
import { C as DRAFT_STORE_METHODS, D as invalidatePluginComponentCache, E as takeDraftOverride, O as matchRscPage, S as PluginManager, T as draftSessionCookie, _ as resolveServices, a as applySSRResult, b as spaceIconsOf, c as withNotFound, f as answerCurrentSpacePreflight, g as resolveRscEndpoint, h as meterPage, i as Component, l as withRefusal, m as handleSpaceDocument, n as prepareRender, o as isReusable, p as handleCurrentSpace, r as imagesStage, s as renderParamsOf, t as buildBody, v as resolvePageSeo, w as createMemoryDraftStore, x as iconGlyphsAt, y as ICONS_PATH } from "./buildBody-Bm398uxH.js";
|
|
2
|
+
import { $ as toSharedPage, B as destroyServerCaches, C as googleFontsStage, D as sendScriptPolicy, F as cacheLimitsOf, G as styleSheetOf, I as cacheFilterOf, J as renderLimitFor, M as reportReactBuild, N as normalizePluginSource, P as normalizePlugins, Q as pageHtml, R as shareCache, X as fromSharedPage, Y as renderLimitOf, Z as keepPage, at as ignoredQueryParamsOf, b as escapeHtml, et as buildCacheManager, ft as DEFAULT_TTL_MS, it as offlineDataCacheKeyOf, j as createOfflineDataLoader, nt as buildRscCacheKey, ot as renderedQuery, pt as requestPaintedStateWithDefaults, rt as keepsVersion, st as SCHEME_HINT_HEADER, tt as buildHtmlCacheKey, ut as DEFAULT_CACHE_BYTES, y as RequestMetrics, z as createServerCaches } from "./core-CoKORAOg.js";
|
|
3
3
|
import { n as renewForNavigation, t as isDocumentNavigation } from "./renewal-D98v6-Jd.js";
|
|
4
4
|
import { t as compileTemplate } from "./template-M3IEZ6os.js";
|
|
5
5
|
import { n as createRateLimit, t as RATE_LIMIT_METHODS } from "./throttle-CRiZB6_A.js";
|
|
6
|
+
import { n as pageAssets, r as resolveSdkAssetsDir } from "./sdkAssets-CXGoc_WE.js";
|
|
6
7
|
import { dataDirLookup } from "@plitzi/sdk-kernel/data";
|
|
7
8
|
import { cappedResponse, fetchOutbound, privateOriginsOf } from "@plitzi/sdk-kernel/outbound";
|
|
8
9
|
import { DEFAULT_FAVICON, PLITZI_MARK_SVG, RSC_FAILURE, blockedAiCrawlers, collectServerElements, inputProviders, inputReadings, pageAccessOf, pageAccessRefusal, serverInputOf, serverProviderSource, serverQueryOf, serverWhenValues, whenOf, whenProviders, whenUnknownToServer, withholdPages } from "@plitzi/sdk-shared/schema";
|
|
9
10
|
import http from "node:http";
|
|
10
11
|
import https from "node:https";
|
|
11
|
-
import
|
|
12
|
+
import { readFile } from "node:fs/promises";
|
|
12
13
|
import path from "node:path";
|
|
13
14
|
import { PROJECT_DATA_PREFIX } from "@plitzi/sdk-shared/project/paths";
|
|
14
15
|
import { broadcast, configStaticStage, createHttpServer, createMiddlewaresStage, crossSiteWritesStage, fleetRole, fleetStore, healthStage, hostable, isNavigation, makeHandler, onAbort, onBroadcast, openEventStream, publicDirStage, readRawBody, refusedCrossSite, requestAuthority, requestOrigin, resolveCompression, resolveWorkers, safeRedirectTarget, serveStatic, wellKnownStage } from "@plitzi/sdk-kernel/http";
|
|
@@ -22,11 +23,8 @@ import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
|
22
23
|
import { knowHostDeployment } from "@plitzi/sdk-kernel/deployment";
|
|
23
24
|
import { PREVIEW_TOKEN_PARAM, appendCookies, clearSessionCookies, readCookies, readDraftToken, readRenewalGuard, readSessionHint, readSessionToken, resolveDebugAuthorization, writeRenewalGuard, writeSessionCookies } from "@plitzi/sdk-kernel/identity";
|
|
24
25
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
25
|
-
import { STYLE_SHEET_PATH
|
|
26
|
-
import
|
|
27
|
-
import { copyFileAtomic, writeFileAtomic } from "@plitzi/sdk-kernel/files";
|
|
28
|
-
import { esbuildBuild } from "@plitzi/sdk-kernel/build";
|
|
29
|
-
import { pluginAssetLoaders, pluginImportQueries } from "@plitzi/sdk-shared/plugins/bundle";
|
|
26
|
+
import { STYLE_SHEET_PATH } from "@plitzi/sdk-shared/style";
|
|
27
|
+
import { watch } from "node:fs";
|
|
30
28
|
import { statsStage } from "@plitzi/sdk-kernel/stats";
|
|
31
29
|
import { renderToPipeableStream } from "react-dom/server";
|
|
32
30
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -761,601 +759,11 @@ var seconds = (ms) => `${Math.round(ms / 1e3)} s`;
|
|
|
761
759
|
*/
|
|
762
760
|
var reportCacheSharing = (config, { ttlMs, bus, store }) => {
|
|
763
761
|
if (config.devMode && !bus && !store) return;
|
|
764
|
-
const kept = `Pages are kept ${seconds(ttlMs)} (served ${seconds(config.cache?.staleMs ?? DEFAULT_TTL_MS
|
|
762
|
+
const kept = `Pages are kept ${seconds(ttlMs)} (served ${seconds(config.cache?.staleMs ?? DEFAULT_TTL_MS.stale)} more while rendered again), up to ${megabytes(config.cache?.maxBytes ?? DEFAULT_CACHE_BYTES.html)} a process`;
|
|
765
763
|
const where = store ? ", and shared by every replica (cache.store)" : ", each process its own";
|
|
766
764
|
const reach = bus ? "an invalidation reaches every replica (cache.bus)." : "an invalidation reaches this host's processes only — with several replicas, give the server cache.bus (createRedisPubSub) or each serves what a write made untrue until its copy expires.";
|
|
767
765
|
serverLog.info("SSR cache", `${kept}${where}; ${reach}`);
|
|
768
766
|
};
|
|
769
|
-
// src/plugins/compile.ts
|
|
770
|
-
var EXTERNAL = [
|
|
771
|
-
"react",
|
|
772
|
-
"react-dom",
|
|
773
|
-
"react-dom/client",
|
|
774
|
-
"react/jsx-runtime",
|
|
775
|
-
"@plitzi/plitzi-sdk",
|
|
776
|
-
"@plitzi/sdk-shared"
|
|
777
|
-
];
|
|
778
|
-
/**
|
|
779
|
-
* Everything that went into the bundle, so a server can tell when any of it has moved on: a dev server as it is
|
|
780
|
-
* edited, and any server — a deployment — when it finds a bundle built from something else (its content digest).
|
|
781
|
-
*
|
|
782
|
-
* The entry file is one file and a plugin is a directory: a component edited beside its `index.ts` leaves the entry's
|
|
783
|
-
* timestamp exactly where it was, and a watcher looking only at that never rebuilds. esbuild already knows the answer
|
|
784
|
-
* — this is its own list of inputs — so nothing has to be guessed from the file system.
|
|
785
|
-
*
|
|
786
|
-
* Dependencies are left out. They change when something is installed, which is not an edit anybody is waiting to see,
|
|
787
|
-
* and stat'ing a few thousand files on every cache miss to find that out is a real cost for no answer.
|
|
788
|
-
*/
|
|
789
|
-
var sourceInputs = (metafile) => metafile ? Object.keys(metafile.inputs).filter((input) => !input.includes("node_modules")).map((input) => path.resolve(input.replace(/^plitzi-(raw|inline):/, ""))) : [];
|
|
790
|
-
var compilePlugin = async (jsPath, outDir, devMode = false) => {
|
|
791
|
-
const result = await esbuildBuild({
|
|
792
|
-
entryPoints: [jsPath],
|
|
793
|
-
bundle: true,
|
|
794
|
-
format: "esm",
|
|
795
|
-
external: EXTERNAL,
|
|
796
|
-
loader: pluginAssetLoaders(),
|
|
797
|
-
plugins: [pluginImportQueries()],
|
|
798
|
-
outdir: outDir,
|
|
799
|
-
entryNames: "index",
|
|
800
|
-
jsx: "automatic",
|
|
801
|
-
minify: !devMode,
|
|
802
|
-
splitting: false,
|
|
803
|
-
logLevel: "warning",
|
|
804
|
-
metafile: true,
|
|
805
|
-
write: false
|
|
806
|
-
});
|
|
807
|
-
await fs.mkdir(outDir, { recursive: true });
|
|
808
|
-
await Promise.all(result.outputFiles.map((output) => writeFileAtomic(output.path, output.path.endsWith(".css") ? inPluginLayer(output.text) : output.contents)));
|
|
809
|
-
return {
|
|
810
|
-
hasCSS: result.outputFiles.some((output) => path.basename(output.path) === "index.css"),
|
|
811
|
-
inputs: sourceInputs(result.metafile)
|
|
812
|
-
};
|
|
813
|
-
};
|
|
814
|
-
// src/plugins/copy.ts
|
|
815
|
-
var copyPlugin = async (src, destDir, filename) => {
|
|
816
|
-
const dest = path.join(destDir, filename);
|
|
817
|
-
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
818
|
-
const res = await fetch(src);
|
|
819
|
-
if (!res.ok) throw new Error(`[SSR] Plugin fetch failed ${src}: ${res.status}`);
|
|
820
|
-
await writeFileAtomic(dest, await res.text());
|
|
821
|
-
} else await copyFileAtomic(src, dest);
|
|
822
|
-
};
|
|
823
|
-
/**
|
|
824
|
-
* A plugin's stylesheet, copied or downloaded into the cache in the plugins' cascade layer — below the space's styles,
|
|
825
|
-
* as a compiled one is — whatever the file it came from says.
|
|
826
|
-
*/
|
|
827
|
-
var copyPluginStylesheet = async (src, destDir) => {
|
|
828
|
-
let css;
|
|
829
|
-
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
830
|
-
const res = await fetch(src);
|
|
831
|
-
if (!res.ok) throw new Error(`[SSR] Plugin stylesheet fetch failed ${src}: ${res.status}`);
|
|
832
|
-
css = await res.text();
|
|
833
|
-
} else css = await fs.readFile(src, "utf8");
|
|
834
|
-
await writeFileAtomic(path.join(destDir, "index.css"), inPluginLayer(css));
|
|
835
|
-
};
|
|
836
|
-
// src/plugins/detect.ts
|
|
837
|
-
var isComponentSource = (source) => "component" in source;
|
|
838
|
-
var detectAction = (js) => {
|
|
839
|
-
if (js.startsWith("http://") || js.startsWith("https://")) return "copy";
|
|
840
|
-
if (js.endsWith(".tsx") || js.endsWith(".ts") || js.endsWith(".jsx")) return "compile";
|
|
841
|
-
return "copy";
|
|
842
|
-
};
|
|
843
|
-
// src/plugins/validate.ts
|
|
844
|
-
var isRemote = (js) => js.startsWith("http://") || js.startsWith("https://");
|
|
845
|
-
/** The file a plugin source needs on disk, or null when nothing local is involved — a remote URL (fetched and
|
|
846
|
-
* cached at request time) or a component handed in directly. */
|
|
847
|
-
var localSourcePath = (source) => {
|
|
848
|
-
if (isComponentSource(source) || isRemote(source.js)) return null;
|
|
849
|
-
return source.js;
|
|
850
|
-
};
|
|
851
|
-
/** Fail at boot on a plugin whose entry file is missing. A plugin entry is a plain string path in the server
|
|
852
|
-
* config, so nothing — not tsc, not eslint — notices when that file is moved or deleted; without this check the
|
|
853
|
-
* server starts happily and only dies on the first render that needs the plugin, with an esbuild resolve error
|
|
854
|
-
* far from its cause. */
|
|
855
|
-
var assertPluginSources = (plugins) => {
|
|
856
|
-
const missing = Object.entries(plugins).map(([name, source]) => ({
|
|
857
|
-
name,
|
|
858
|
-
file: localSourcePath(source)
|
|
859
|
-
})).filter((entry) => entry.file !== null && !fs$1.existsSync(entry.file)).map((entry) => ` ${entry.name}: ${entry.file ?? ""}`);
|
|
860
|
-
if (missing.length > 0) throw new Error(`Plugin entry file not found (declared in the server config):\n${missing.join("\n")}`);
|
|
861
|
-
};
|
|
862
|
-
// src/plugins/manager.ts
|
|
863
|
-
var META_FILE = "meta.json";
|
|
864
|
-
var DEFAULT_TTL_MS = 6048e5;
|
|
865
|
-
var DEFAULT_CACHE_DIR = "tmp/.sdk-plugins";
|
|
866
|
-
/** How long a rebuild of vanished bundles waits, once none is pending, for another of the same render to be noticed. */
|
|
867
|
-
var RESTORE_SETTLE_MS = 100;
|
|
868
|
-
/** One hash over every input's path and content — a file gone counts as changed, like a file edited. */
|
|
869
|
-
var digestOf = async (files) => {
|
|
870
|
-
const hash = createHash("sha256");
|
|
871
|
-
for (const file of [...files].sort()) {
|
|
872
|
-
hash.update(file);
|
|
873
|
-
hash.update("\0");
|
|
874
|
-
hash.update(await fs.readFile(file).catch(() => Buffer.from("\0missing")));
|
|
875
|
-
}
|
|
876
|
-
return hash.digest("hex");
|
|
877
|
-
};
|
|
878
|
-
/**
|
|
879
|
-
* Whether a key is this plugin — every version of it, or with `version` that one release — counting the sources a
|
|
880
|
-
* render named under it (`name@1.0.0+<identity>`, see {@link PluginManager.ensure}).
|
|
881
|
-
*/
|
|
882
|
-
var isKeyOf = (key, name, version) => {
|
|
883
|
-
if (version) return key === `${name}@${version}` || key.startsWith(`${name}@${version}+`);
|
|
884
|
-
return key === name || key.startsWith(`${name}@`);
|
|
885
|
-
};
|
|
886
|
-
/**
|
|
887
|
-
* How often a dev server re-asks whether a cached plugin is still current.
|
|
888
|
-
*
|
|
889
|
-
* The check is a handful of `stat`s and this runs on every render, so it is throttled rather than free — a second is
|
|
890
|
-
* far below what anybody notices between saving a file and reloading a page, and far above per-request.
|
|
891
|
-
*/
|
|
892
|
-
var STALE_CHECK_MS = 1e3;
|
|
893
|
-
var PluginManager = class {
|
|
894
|
-
urlPrefix = "/sdk-plugins";
|
|
895
|
-
outputDir;
|
|
896
|
-
plugins;
|
|
897
|
-
ttlMs;
|
|
898
|
-
mem = /* @__PURE__ */ new Map();
|
|
899
|
-
inflight = /* @__PURE__ */ new Map();
|
|
900
|
-
failed = /* @__PURE__ */ new Set();
|
|
901
|
-
/** Maps base plugin name → most recently registered effective key (may include @version) */
|
|
902
|
-
nameIndex = /* @__PURE__ */ new Map();
|
|
903
|
-
devMode = false;
|
|
904
|
-
/** Who is told what each built plugin was built from — a dev server's watcher (`watchPluginSources`). */
|
|
905
|
-
sourceListeners = /* @__PURE__ */ new Set();
|
|
906
|
-
/** The bundles being built again because they vanished from disk under this server — see `restore`. */
|
|
907
|
-
restoring;
|
|
908
|
-
constructor(plugins, cacheDir, ttlMs, devMode = false) {
|
|
909
|
-
assertPluginSources(plugins);
|
|
910
|
-
this.plugins = plugins;
|
|
911
|
-
this.outputDir = path.resolve(process.cwd(), cacheDir ?? DEFAULT_CACHE_DIR);
|
|
912
|
-
this.ttlMs = ttlMs ?? DEFAULT_TTL_MS;
|
|
913
|
-
this.devMode = devMode;
|
|
914
|
-
for (const key of Object.keys(plugins)) {
|
|
915
|
-
const baseName = key.replace(/@[^@]*$/, "");
|
|
916
|
-
this.nameIndex.set(baseName, key);
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
/**
|
|
920
|
-
* Tells `listener` the files every built plugin was built from — those built so far, at once, and each one built or
|
|
921
|
-
* found built from now on. Only a compiled plugin has any: a copied or downloaded one is not this server's source.
|
|
922
|
-
*/
|
|
923
|
-
onSources(listener) {
|
|
924
|
-
this.sourceListeners.add(listener);
|
|
925
|
-
this.mem.forEach((cached, key) => {
|
|
926
|
-
if (cached.inputs?.length) listener(key, cached.inputs);
|
|
927
|
-
});
|
|
928
|
-
return () => {
|
|
929
|
-
this.sourceListeners.delete(listener);
|
|
930
|
-
};
|
|
931
|
-
}
|
|
932
|
-
/**
|
|
933
|
-
* Builds a plugin again because its source changed — and again after a build that failed, which `prepare` otherwise
|
|
934
|
-
* never retries: the edit that fixes a syntax error is exactly the one a dev server must not ignore.
|
|
935
|
-
*/
|
|
936
|
-
async rebuild(name) {
|
|
937
|
-
const key = this.resolveKey(name) ?? name;
|
|
938
|
-
this.mem.delete(key);
|
|
939
|
-
this.failed.delete(key);
|
|
940
|
-
return this.prepare(key);
|
|
941
|
-
}
|
|
942
|
-
remember(key, cached) {
|
|
943
|
-
this.mem.set(key, cached);
|
|
944
|
-
const { inputs } = cached;
|
|
945
|
-
if (inputs?.length) this.sourceListeners.forEach((listener) => {
|
|
946
|
-
listener(key, inputs);
|
|
947
|
-
});
|
|
948
|
-
}
|
|
949
|
-
hasPlugin(name) {
|
|
950
|
-
return this.resolveKey(name) !== null;
|
|
951
|
-
}
|
|
952
|
-
/**
|
|
953
|
-
* A plugin no longer there — its folder removed under a dev server: never built again, nothing of it remembered. A run's
|
|
954
|
-
* preview logged "build failed … Could not resolve" for a plugin a task had deleted, build after build.
|
|
955
|
-
*/
|
|
956
|
-
unregister(name) {
|
|
957
|
-
const base = name.replace(/@[^@]*$/, "");
|
|
958
|
-
for (const key of Object.keys(this.plugins).filter((each) => each.replace(/@[^@]*$/, "") === base)) Reflect.deleteProperty(this.plugins, key);
|
|
959
|
-
this.forget(base);
|
|
960
|
-
}
|
|
961
|
-
register(name, source) {
|
|
962
|
-
this.plugins[name] = source;
|
|
963
|
-
this.mem.delete(name);
|
|
964
|
-
this.failed.delete(name);
|
|
965
|
-
const baseName = name.replace(/@[^@]*$/, "");
|
|
966
|
-
this.nameIndex.set(baseName, name);
|
|
967
|
-
}
|
|
968
|
-
/**
|
|
969
|
-
* Keeps a source a render names, and returns the key to pass to getEntries(): `name@version+<identity>`, or
|
|
970
|
-
* `name@<identity>` without a version.
|
|
971
|
-
*
|
|
972
|
-
* The identity is what the source IS — where its files are, how they are served, the props it carries — because a
|
|
973
|
-
* name and a version are only what its author said about it. Keyed on those alone, the first source to arrive held
|
|
974
|
-
* the key for as long as the process ran: a plugin published again under the same version kept its old, now missing
|
|
975
|
-
* URLs, and two spaces each with a `board@1.0.0` of their own were served whichever this process had met first.
|
|
976
|
-
* Worked out from the source rather than handed out in order of arrival, so every worker names one source the same
|
|
977
|
-
* way — the key is also the folder a built bundle is written to, and all of them share it.
|
|
978
|
-
*
|
|
979
|
-
* Never taken as what a bare name means: {@link resolveKey} answers for the plugins this server was set up with, not
|
|
980
|
-
* for whichever space rendered last.
|
|
981
|
-
*/
|
|
982
|
-
ensure(name, source) {
|
|
983
|
-
const identity = createHash("sha256").update(JSON.stringify([
|
|
984
|
-
source.js,
|
|
985
|
-
source.css,
|
|
986
|
-
isComponentSource(source) ? void 0 : source.action,
|
|
987
|
-
source.props
|
|
988
|
-
])).digest("hex").slice(0, 12);
|
|
989
|
-
const key = `${name}@${source.version ? `${source.version}+` : ""}${identity}`;
|
|
990
|
-
if (!(key in this.plugins)) this.plugins[key] = source;
|
|
991
|
-
return key;
|
|
992
|
-
}
|
|
993
|
-
/**
|
|
994
|
-
* Resolves a caller-supplied name to the effective key stored in the plugins map.
|
|
995
|
-
* Accepts both the exact key (`plitziBuilder@1.0.0`) and the base name (`plitziBuilder`).
|
|
996
|
-
*/
|
|
997
|
-
resolveKey(name) {
|
|
998
|
-
if (name in this.plugins) return name;
|
|
999
|
-
const indexed = this.nameIndex.get(name);
|
|
1000
|
-
if (indexed && indexed in this.plugins) return indexed;
|
|
1001
|
-
return null;
|
|
1002
|
-
}
|
|
1003
|
-
pluginDir(name) {
|
|
1004
|
-
return path.join(this.outputDir, name);
|
|
1005
|
-
}
|
|
1006
|
-
isExpired(compiledAt) {
|
|
1007
|
-
return Date.now() - compiledAt > this.ttlMs;
|
|
1008
|
-
}
|
|
1009
|
-
/**
|
|
1010
|
-
* Whether anything the bundle was built from has moved on since. Dev mode only.
|
|
1011
|
-
*
|
|
1012
|
-
* The cache is keyed on time and version, neither of which changes when somebody edits a component: a versioned
|
|
1013
|
-
* plugin never expires and an unversioned one lasts a week, so a change to the source showed up nowhere and the
|
|
1014
|
-
* server kept serving the bundle it built the first time. In production that is exactly right — a deployment's
|
|
1015
|
-
* plugins do not change under it — and while somebody is writing one it is a file that appears to do nothing.
|
|
1016
|
-
*
|
|
1017
|
-
* Every INPUT, not the entry file. A plugin is a directory and the entry is usually a barrel that re-exports it, so
|
|
1018
|
-
* watching only `source.js` answers "nothing has changed" to every edit anybody actually makes — the file whose
|
|
1019
|
-
* timestamp moves is the component next to it. The list comes from the build itself (see `compilePlugin`), so it is
|
|
1020
|
-
* exactly what went in, including a file imported from another plugin's folder. A bundle built before this existed
|
|
1021
|
-
* has no list, and falls back to the entry file rather than claiming to be fresh.
|
|
1022
|
-
*/
|
|
1023
|
-
/**
|
|
1024
|
-
* The same question of the entry this process is holding, asked at most once a second.
|
|
1025
|
-
*
|
|
1026
|
-
* `checkedAt` is stamped on the cached entry rather than kept in a second map, so it cannot outlive what it is about.
|
|
1027
|
-
*/
|
|
1028
|
-
async isStaleInMemory(cached, source) {
|
|
1029
|
-
if (!this.devMode) return false;
|
|
1030
|
-
const now = Date.now();
|
|
1031
|
-
if (cached.checkedAt && now - cached.checkedAt < STALE_CHECK_MS) return false;
|
|
1032
|
-
cached.checkedAt = now;
|
|
1033
|
-
return this.isStale({
|
|
1034
|
-
compiledAt: cached.compiledAt,
|
|
1035
|
-
inputs: cached.inputs
|
|
1036
|
-
}, source);
|
|
1037
|
-
}
|
|
1038
|
-
/**
|
|
1039
|
-
* Whether what a bundle on disk was built from reads differently now — asked once, when a process first finds the
|
|
1040
|
-
* bundle, in production as much as in development.
|
|
1041
|
-
*
|
|
1042
|
-
* A version names a release, and a release is only as good as whoever bumps it: a deployment rebuilt from new source
|
|
1043
|
-
* under the same version found last deployment's bundle in its cache folder and served it, with nothing anywhere
|
|
1044
|
-
* saying so. The content decides instead. A bundle written before digests were recorded has none, and is built again
|
|
1045
|
-
* once. What this server does not build from files — a download, a CDN, a component — is its version's business.
|
|
1046
|
-
*/
|
|
1047
|
-
async contentChanged(meta, source) {
|
|
1048
|
-
const inputs = this.inputsOf(source, meta.inputs ?? []);
|
|
1049
|
-
if (inputs.length === 0) return false;
|
|
1050
|
-
return meta.digest !== await digestOf(inputs);
|
|
1051
|
-
}
|
|
1052
|
-
/** The local files a bundle is built from: what the compiler reported, or the files it was copied from. */
|
|
1053
|
-
inputsOf(source, compiled) {
|
|
1054
|
-
if (isComponentSource(source) || source.action === "download" || source.action === "cdn") return [];
|
|
1055
|
-
if (compiled.length > 0) return compiled;
|
|
1056
|
-
return [source.js, source.css].filter((file) => typeof file === "string" && file !== "" && !/^https?:\/\//.test(file));
|
|
1057
|
-
}
|
|
1058
|
-
async isStale(meta, source) {
|
|
1059
|
-
if (!this.devMode || !source.js || /^https?:\/\//.test(source.js) || isComponentSource(source)) return false;
|
|
1060
|
-
const watched = meta.inputs?.length ? meta.inputs : [source.js];
|
|
1061
|
-
if (meta.inputs?.length) {
|
|
1062
|
-
const entry = await fs.realpath(source.js).catch(() => path.resolve(source.js));
|
|
1063
|
-
if (!meta.inputs.includes(entry)) return true;
|
|
1064
|
-
}
|
|
1065
|
-
return (await Promise.all(watched.map((file) => fs.stat(file).then((stats) => stats.mtimeMs).catch(() => Number.POSITIVE_INFINITY)))).some((modifiedAt) => modifiedAt > meta.compiledAt);
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* The bundle's URL, stamped with when it was built.
|
|
1069
|
-
*
|
|
1070
|
-
* Plugin assets are served `immutable` for a year, which is right for a file whose URL identifies its contents
|
|
1071
|
-
* and catastrophic for one whose URL never changes: a browser told a resource is immutable does not revalidate
|
|
1072
|
-
* it at all — no conditional request, no ETag — so a rebuilt plugin never reaches anyone who had already loaded
|
|
1073
|
-
* the old one. Not a stale render either: the page's own CSS is fresh while the plugin's is a year old, and the
|
|
1074
|
-
* two disagree in ways nobody can read. The stamp is what makes the promise true.
|
|
1075
|
-
*/
|
|
1076
|
-
assetUrl(name, file, compiledAt) {
|
|
1077
|
-
return `${this.urlPrefix}/${name}/${file}?v=${compiledAt.toString(36)}`;
|
|
1078
|
-
}
|
|
1079
|
-
toEntry(name, hasJS, cssUrl, props = {}, compiledAt = 0) {
|
|
1080
|
-
const keyName = name.split("@")[0];
|
|
1081
|
-
return {
|
|
1082
|
-
name,
|
|
1083
|
-
varName: keyName.split("-").join("_").split(".").join("_"),
|
|
1084
|
-
keyName,
|
|
1085
|
-
js: hasJS ? this.assetUrl(name, "index.js", compiledAt) : void 0,
|
|
1086
|
-
filePath: hasJS ? path.join(this.outputDir, name, "index.js") : void 0,
|
|
1087
|
-
css: cssUrl,
|
|
1088
|
-
props
|
|
1089
|
-
};
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* A plugin served from where it was published, with nothing on this server's disk.
|
|
1093
|
-
*
|
|
1094
|
-
* No `filePath`, which is the whole point: `loadPluginComponents` only imports entries that have one, so a
|
|
1095
|
-
* bundle this server did not build never enters the render process — and cannot bring a second copy of React
|
|
1096
|
-
* in with it. The template already imports `js` in the browser, so the plugin still renders, just on the
|
|
1097
|
-
* client.
|
|
1098
|
-
*/
|
|
1099
|
-
toRemoteEntry(name, source) {
|
|
1100
|
-
const keyName = name.split("@")[0];
|
|
1101
|
-
return {
|
|
1102
|
-
name,
|
|
1103
|
-
varName: keyName.split("-").join("_").split(".").join("_"),
|
|
1104
|
-
keyName,
|
|
1105
|
-
js: source.js,
|
|
1106
|
-
css: source.css,
|
|
1107
|
-
props: source.props ?? {}
|
|
1108
|
-
};
|
|
1109
|
-
}
|
|
1110
|
-
isWebUrl(s) {
|
|
1111
|
-
return s.startsWith("/") || s.startsWith("http://") || s.startsWith("https://");
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* Builds every registered plugin now rather than on first use. A primary does it before starting its workers, so
|
|
1115
|
-
* the workers find each one built — instead of all of them compiling the same plugin into the same folder at once.
|
|
1116
|
-
*/
|
|
1117
|
-
async prepareAll() {
|
|
1118
|
-
await Promise.all(Object.keys(this.plugins).map((key) => this.prepare(key)));
|
|
1119
|
-
}
|
|
1120
|
-
async prepare(name) {
|
|
1121
|
-
const key = this.resolveKey(name) ?? name;
|
|
1122
|
-
if (this.failed.has(key)) return null;
|
|
1123
|
-
const inflight = this.inflight.get(key);
|
|
1124
|
-
if (inflight !== void 0) return inflight;
|
|
1125
|
-
const source = this.plugins[key];
|
|
1126
|
-
if (source === void 0) return null;
|
|
1127
|
-
if (isComponentSource(source) && !source.js) return this.toEntry(key, false, void 0, source.props);
|
|
1128
|
-
if (!isComponentSource(source) && source.action === "cdn") return this.toRemoteEntry(key, source);
|
|
1129
|
-
const cached = this.mem.get(key);
|
|
1130
|
-
let missing = false;
|
|
1131
|
-
if (cached && !this.isExpired(cached.compiledAt)) {
|
|
1132
|
-
if (await this.fileExists(path.join(this.pluginDir(key), "index.js"))) {
|
|
1133
|
-
/**
|
|
1134
|
-
* The disk check below never runs while this process holds the entry in memory, and a versioned plugin never
|
|
1135
|
-
* expires — so without this a dev server serves the bundle it built when it started, for as long as it runs.
|
|
1136
|
-
* Nothing else brings it back either: the components are named by PATH rather than imported, so editing one
|
|
1137
|
-
* does not even restart the watcher.
|
|
1138
|
-
*/
|
|
1139
|
-
if (!await this.isStaleInMemory(cached, source)) return cached.entry;
|
|
1140
|
-
serverLog.info("SSR", `Plugin "${key}" source changed since it was built, rebuilding…`);
|
|
1141
|
-
this.mem.delete(key);
|
|
1142
|
-
await fs.rm(this.pluginDir(key), {
|
|
1143
|
-
recursive: true,
|
|
1144
|
-
force: true
|
|
1145
|
-
});
|
|
1146
|
-
} else {
|
|
1147
|
-
serverLog.info("SSR", `Plugin "${key}" output missing, rebuilding…`);
|
|
1148
|
-
this.mem.delete(key);
|
|
1149
|
-
missing = true;
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
const meta = await this.readMeta(key);
|
|
1153
|
-
if (meta) {
|
|
1154
|
-
const sourceVersion = source.version;
|
|
1155
|
-
if (await this.isStale(meta, source) || await this.contentChanged(meta, source)) {
|
|
1156
|
-
serverLog.info("SSR", `Plugin "${key}" source changed since it was built, rebuilding…`);
|
|
1157
|
-
await fs.rm(this.pluginDir(key), {
|
|
1158
|
-
recursive: true,
|
|
1159
|
-
force: true
|
|
1160
|
-
});
|
|
1161
|
-
} else if (sourceVersion && meta.version !== sourceVersion) {
|
|
1162
|
-
serverLog.info("SSR", `Plugin "${key}" version changed (${meta.version ?? "none"} → ${sourceVersion}), rebuilding…`);
|
|
1163
|
-
await fs.rm(this.pluginDir(key), {
|
|
1164
|
-
recursive: true,
|
|
1165
|
-
force: true
|
|
1166
|
-
});
|
|
1167
|
-
} else if (sourceVersion || !this.isExpired(meta.compiledAt)) {
|
|
1168
|
-
if (await this.fileExists(path.join(this.pluginDir(key), "index.js"))) {
|
|
1169
|
-
const sourceCss = source.css;
|
|
1170
|
-
let cssUrl;
|
|
1171
|
-
if (await this.fileExists(path.join(this.pluginDir(key), "index.css"))) cssUrl = this.assetUrl(key, "index.css", meta.compiledAt);
|
|
1172
|
-
else if (sourceCss && this.isWebUrl(sourceCss)) cssUrl = sourceCss;
|
|
1173
|
-
const entry = this.toEntry(key, true, cssUrl, source.props, meta.compiledAt);
|
|
1174
|
-
this.remember(key, {
|
|
1175
|
-
compiledAt: meta.compiledAt,
|
|
1176
|
-
entry,
|
|
1177
|
-
inputs: meta.inputs
|
|
1178
|
-
});
|
|
1179
|
-
return entry;
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
const promise = this.build(key, source).finally(() => this.inflight.delete(key));
|
|
1184
|
-
this.inflight.set(key, promise);
|
|
1185
|
-
if (missing) this.restore(key, promise);
|
|
1186
|
-
return promise;
|
|
1187
|
-
}
|
|
1188
|
-
/**
|
|
1189
|
-
* Bundles that vanished from disk under a running server are built again as one episode: said once when the first
|
|
1190
|
-
* is noticed and once when the last is built — how many, how long, which failed — at the level it was noticed at.
|
|
1191
|
-
* Said per plugin, it was a warning for each and a "ready" for each at a level a project's terminal does not show,
|
|
1192
|
-
* so the rebuild never said it had finished.
|
|
1193
|
-
*/
|
|
1194
|
-
restore(key, build) {
|
|
1195
|
-
if (!this.restoring) {
|
|
1196
|
-
this.restoring = {
|
|
1197
|
-
started: Date.now(),
|
|
1198
|
-
pending: /* @__PURE__ */ new Set(),
|
|
1199
|
-
rebuilt: 0,
|
|
1200
|
-
failed: []
|
|
1201
|
-
};
|
|
1202
|
-
const where = path.relative(process.cwd(), this.outputDir) || this.outputDir;
|
|
1203
|
-
serverLog.warn("SSR", `Plugin bundles missing from ${where}: building them again…`);
|
|
1204
|
-
}
|
|
1205
|
-
const episode = this.restoring;
|
|
1206
|
-
clearTimeout(episode.closing);
|
|
1207
|
-
episode.pending.add(key);
|
|
1208
|
-
build.then((entry) => {
|
|
1209
|
-
episode.pending.delete(key);
|
|
1210
|
-
if (entry) episode.rebuilt += 1;
|
|
1211
|
-
else episode.failed.push(key);
|
|
1212
|
-
if (episode.pending.size > 0) return;
|
|
1213
|
-
episode.closing = setTimeout(() => {
|
|
1214
|
-
if (this.restoring !== episode || episode.pending.size > 0) return;
|
|
1215
|
-
this.restoring = void 0;
|
|
1216
|
-
const seconds = ((Date.now() - episode.started) / 1e3).toFixed(1);
|
|
1217
|
-
const failed = episode.failed.length > 0 ? ` — ${String(episode.failed.length)} failed (${episode.failed.join(", ")}), said above` : "";
|
|
1218
|
-
serverLog.warn("SSR", `Plugin bundles built again: ${String(episode.rebuilt)} in ${seconds}s${failed}`);
|
|
1219
|
-
}, RESTORE_SETTLE_MS);
|
|
1220
|
-
episode.closing.unref();
|
|
1221
|
-
});
|
|
1222
|
-
}
|
|
1223
|
-
async build(name, source) {
|
|
1224
|
-
const dir = this.pluginDir(name);
|
|
1225
|
-
await fs.mkdir(dir, { recursive: true });
|
|
1226
|
-
const jsPath = source.js;
|
|
1227
|
-
const cssPath = source.css;
|
|
1228
|
-
const action = isComponentSource(source) ? source.js ? detectAction(source.js) : void 0 : source.action ?? detectAction(source.js);
|
|
1229
|
-
if (!jsPath || !action) return this.toEntry(name, false, void 0, source.props);
|
|
1230
|
-
serverLog.info("SSR", `Plugin "${name}" building (${action}: ${jsPath})…`);
|
|
1231
|
-
try {
|
|
1232
|
-
let cssUrl;
|
|
1233
|
-
let buildInputs = [];
|
|
1234
|
-
if (action === "compile") {
|
|
1235
|
-
const { hasCSS, inputs } = await compilePlugin(jsPath, dir, this.devMode);
|
|
1236
|
-
buildInputs = inputs;
|
|
1237
|
-
if (hasCSS) cssUrl = `${this.urlPrefix}/${name}/index.css`;
|
|
1238
|
-
else if (cssPath) {
|
|
1239
|
-
if (this.isWebUrl(cssPath)) cssUrl = cssPath;
|
|
1240
|
-
else {
|
|
1241
|
-
await copyPluginStylesheet(cssPath, dir);
|
|
1242
|
-
cssUrl = `${this.urlPrefix}/${name}/index.css`;
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
} else if (action === "download") {
|
|
1246
|
-
const jsRes = await fetch(jsPath);
|
|
1247
|
-
if (!jsRes.ok) throw new Error(`HTTP ${jsRes.status} downloading ${jsPath}`);
|
|
1248
|
-
await writeFileAtomic(path.join(dir, "index.js"), await jsRes.text());
|
|
1249
|
-
if (cssPath) {
|
|
1250
|
-
if (cssPath.startsWith("http://") || cssPath.startsWith("https://")) await copyPluginStylesheet(cssPath, dir);
|
|
1251
|
-
else if (this.isWebUrl(cssPath)) cssUrl = cssPath;
|
|
1252
|
-
else await copyPluginStylesheet(cssPath, dir);
|
|
1253
|
-
cssUrl = `${this.urlPrefix}/${name}/index.css`;
|
|
1254
|
-
}
|
|
1255
|
-
} else {
|
|
1256
|
-
await copyPlugin(jsPath, dir, "index.js");
|
|
1257
|
-
if (cssPath) {
|
|
1258
|
-
if (this.isWebUrl(cssPath)) cssUrl = cssPath;
|
|
1259
|
-
else {
|
|
1260
|
-
await copyPluginStylesheet(cssPath, dir);
|
|
1261
|
-
cssUrl = `${this.urlPrefix}/${name}/index.css`;
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
const compiledAt = Date.now();
|
|
1266
|
-
const inputs = this.inputsOf(source, buildInputs);
|
|
1267
|
-
await this.writeMeta(name, {
|
|
1268
|
-
compiledAt,
|
|
1269
|
-
version: source.version,
|
|
1270
|
-
inputs: buildInputs,
|
|
1271
|
-
...inputs.length > 0 ? { digest: await digestOf(inputs) } : {}
|
|
1272
|
-
});
|
|
1273
|
-
if (cssUrl?.startsWith(this.urlPrefix)) cssUrl = this.assetUrl(name, "index.css", compiledAt);
|
|
1274
|
-
const entry = this.toEntry(name, true, cssUrl, source.props, compiledAt);
|
|
1275
|
-
this.remember(name, {
|
|
1276
|
-
compiledAt,
|
|
1277
|
-
entry,
|
|
1278
|
-
inputs: buildInputs
|
|
1279
|
-
});
|
|
1280
|
-
serverLog.info("SSR", `Plugin "${name}" ready → ${entry.js}`);
|
|
1281
|
-
return entry;
|
|
1282
|
-
} catch (err) {
|
|
1283
|
-
serverLog.error("SSR", `Plugin "${name}" build failed (js: ${source.js ?? "none"})`, err);
|
|
1284
|
-
this.failed.add(name);
|
|
1285
|
-
return null;
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
async getEntries(names) {
|
|
1289
|
-
if (names.length === 0) return [];
|
|
1290
|
-
return (await Promise.all(names.map((n) => this.prepare(n)))).filter((e) => e !== null && e.js !== void 0);
|
|
1291
|
-
}
|
|
1292
|
-
getComponents() {
|
|
1293
|
-
const out = {};
|
|
1294
|
-
for (const [name, source] of Object.entries(this.plugins)) if (isComponentSource(source)) out[name.replace(/@[^@]*$/, "")] = source.component;
|
|
1295
|
-
return out;
|
|
1296
|
-
}
|
|
1297
|
-
/**
|
|
1298
|
-
* Drops what this process remembers of a plugin — its entry, its failure, which version its name means — and
|
|
1299
|
-
* leaves the disk alone. What an invalidation elsewhere in the fleet does here: that process removes the files,
|
|
1300
|
-
* and each of the others only has to stop pointing at them.
|
|
1301
|
-
*/
|
|
1302
|
-
forget(name, version) {
|
|
1303
|
-
if (!name) {
|
|
1304
|
-
this.mem.clear();
|
|
1305
|
-
this.failed.clear();
|
|
1306
|
-
this.nameIndex.clear();
|
|
1307
|
-
return;
|
|
1308
|
-
}
|
|
1309
|
-
const keysToEvict = /* @__PURE__ */ new Set();
|
|
1310
|
-
for (const key of [
|
|
1311
|
-
...Object.keys(this.plugins),
|
|
1312
|
-
...this.mem.keys(),
|
|
1313
|
-
...this.failed
|
|
1314
|
-
]) if (isKeyOf(key, name, version)) keysToEvict.add(key);
|
|
1315
|
-
for (const key of keysToEvict) {
|
|
1316
|
-
this.mem.delete(key);
|
|
1317
|
-
this.failed.delete(key);
|
|
1318
|
-
}
|
|
1319
|
-
const indexed = this.nameIndex.get(name);
|
|
1320
|
-
if (indexed !== void 0 && isKeyOf(indexed, name, version)) this.nameIndex.delete(name);
|
|
1321
|
-
}
|
|
1322
|
-
async invalidate(name, version) {
|
|
1323
|
-
this.forget(name, version);
|
|
1324
|
-
if (!name) {
|
|
1325
|
-
await fs.rm(this.outputDir, {
|
|
1326
|
-
recursive: true,
|
|
1327
|
-
force: true
|
|
1328
|
-
});
|
|
1329
|
-
return;
|
|
1330
|
-
}
|
|
1331
|
-
try {
|
|
1332
|
-
const entries = await fs.readdir(this.outputDir);
|
|
1333
|
-
await Promise.all(entries.filter((entry) => isKeyOf(entry, name, version)).map((entry) => fs.rm(path.join(this.outputDir, entry), {
|
|
1334
|
-
recursive: true,
|
|
1335
|
-
force: true
|
|
1336
|
-
})));
|
|
1337
|
-
} catch {}
|
|
1338
|
-
}
|
|
1339
|
-
destroy() {
|
|
1340
|
-
this.mem.clear();
|
|
1341
|
-
this.failed.clear();
|
|
1342
|
-
this.nameIndex.clear();
|
|
1343
|
-
}
|
|
1344
|
-
async readMeta(name) {
|
|
1345
|
-
try {
|
|
1346
|
-
const raw = await fs.readFile(path.join(this.pluginDir(name), META_FILE), "utf-8");
|
|
1347
|
-
return JSON.parse(raw);
|
|
1348
|
-
} catch {
|
|
1349
|
-
return null;
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1352
|
-
async writeMeta(name, meta) {
|
|
1353
|
-
await writeFileAtomic(path.join(this.pluginDir(name), META_FILE), JSON.stringify(meta));
|
|
1354
|
-
}
|
|
1355
|
-
async fileExists(p) {
|
|
1356
|
-
return fs.access(p).then(() => true).catch(() => false);
|
|
1357
|
-
}
|
|
1358
|
-
};
|
|
1359
767
|
// src/plugins/watch.ts
|
|
1360
768
|
/** How long a burst of writes — an editor saving, formatting, saving again — is waited out before one rebuild. */
|
|
1361
769
|
var SETTLE_MS = 80;
|
|
@@ -1632,17 +1040,25 @@ var llmsTxtStage = async (ctx) => {
|
|
|
1632
1040
|
// src/core/services/robotsTxt.ts
|
|
1633
1041
|
/** What a space that says nothing answers: everything may be crawled. */
|
|
1634
1042
|
var DEFAULT_ROBOTS_TXT = "User-agent: *\nAllow: /\n";
|
|
1043
|
+
/** What an address made for people, never for search, answers (a snapshot's preview): nothing may be crawled. */
|
|
1044
|
+
var NOINDEX_ROBOTS_TXT = "User-agent: *\nDisallow: /\n";
|
|
1635
1045
|
var SITEMAP_LINE = /^\s*sitemap\s*:/im;
|
|
1636
1046
|
/**
|
|
1637
1047
|
* `/robots.txt`: the space's own (`settings.robotsTxt`) or one that lets crawlers read everything, then a `Disallow: /`
|
|
1638
1048
|
* for each AI crawler of the kinds the space keeps out (`settings.blockAiCrawlers`), and the address of its sitemap
|
|
1639
|
-
* unless its own text names one. Never the space's page for an address it has none for: a crawler reads a 404 page as
|
|
1049
|
+
* unless its own text names one — and on an address that is never for search (`noindex`), nothing at all. Never the space's page for an address it has none for: a crawler reads a 404 page as
|
|
1640
1050
|
* "no rules", and an HTML page as rules it cannot parse.
|
|
1641
1051
|
*/
|
|
1642
1052
|
var robotsTxtStage = async (ctx) => {
|
|
1643
1053
|
const { req } = ctx;
|
|
1644
1054
|
if (req.method !== "GET" || req.path !== "/robots.txt") return false;
|
|
1645
1055
|
ctx.operation = "robots";
|
|
1056
|
+
ctx.res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
1057
|
+
if (req.ctx.spaceDeployment?.noindex) {
|
|
1058
|
+
ctx.res.setStatus(200);
|
|
1059
|
+
ctx.res.send(NOINDEX_ROBOTS_TXT);
|
|
1060
|
+
return true;
|
|
1061
|
+
}
|
|
1646
1062
|
const settings = (await servedSpace(ctx, "/robots.txt"))?.schema.settings;
|
|
1647
1063
|
const own = settings?.robotsTxt?.trim() ? settings.robotsTxt.trim() : DEFAULT_ROBOTS_TXT.trim();
|
|
1648
1064
|
const origin = requestOrigin(req);
|
|
@@ -1652,7 +1068,6 @@ var robotsTxtStage = async (ctx) => {
|
|
|
1652
1068
|
...origin && !SITEMAP_LINE.test(own) ? [`Sitemap: ${origin}/sitemap.xml`] : []
|
|
1653
1069
|
];
|
|
1654
1070
|
ctx.res.setStatus(200);
|
|
1655
|
-
ctx.res.setHeader("Content-Type", "text/plain; charset=utf-8");
|
|
1656
1071
|
ctx.res.send(`${sections.join("\n\n")}\n`);
|
|
1657
1072
|
return true;
|
|
1658
1073
|
};
|
|
@@ -1767,7 +1182,7 @@ var handleRsc = async (req, res, config, _pluginManager, cache, signal) => {
|
|
|
1767
1182
|
*/
|
|
1768
1183
|
const forcingFlags = Object.keys(forcedFlagsFromCookies(req.headers.cookie, requestAuthority(req))).length > 0;
|
|
1769
1184
|
const uncached = previewing || forcingFlags;
|
|
1770
|
-
const ttlMs = config.rsc?.cacheTtlMs ?? DEFAULT_TTL_MS
|
|
1185
|
+
const ttlMs = config.rsc?.cacheTtlMs ?? DEFAULT_TTL_MS.rsc;
|
|
1771
1186
|
const isAuthenticated = !!req.ctx.user;
|
|
1772
1187
|
const cacheControl = environment === "main" || uncached ? "no-store" : isAuthenticated ? `private, max-age=${Math.floor(ttlMs / 1e3)}` : `public, max-age=${Math.floor(ttlMs / 1e3)}`;
|
|
1773
1188
|
const cacheKey = environment !== "main" && !uncached ? buildRscCacheKey(spaceId, environment, revision, req.ctx.user?.id, idsParam, req) : void 0;
|
|
@@ -1953,8 +1368,8 @@ var pageSlot = (config, caches, key, facts, anonymous, compression) => {
|
|
|
1953
1368
|
key: sharedKeyOf(key),
|
|
1954
1369
|
facts
|
|
1955
1370
|
} } : {},
|
|
1956
|
-
ttlMs: config.cacheTtlMs ?? DEFAULT_TTL_MS
|
|
1957
|
-
staleMs: config.cache?.staleMs ?? DEFAULT_TTL_MS
|
|
1371
|
+
ttlMs: config.cacheTtlMs ?? DEFAULT_TTL_MS.html,
|
|
1372
|
+
staleMs: config.cache?.staleMs ?? DEFAULT_TTL_MS.stale,
|
|
1958
1373
|
compression
|
|
1959
1374
|
};
|
|
1960
1375
|
};
|
|
@@ -2028,7 +1443,10 @@ var streamBody = async (req, res, config, spaceId, environment, revision, render
|
|
|
2028
1443
|
metrics?.record("template", Math.round(performance.now() - templateStart));
|
|
2029
1444
|
const sentinelIdx = fullTemplate.indexOf(SSR_SENTINEL);
|
|
2030
1445
|
const head = sentinelIdx >= 0 ? fullTemplate.slice(0, sentinelIdx) : fullTemplate;
|
|
2031
|
-
const
|
|
1446
|
+
const tailOf = (template) => {
|
|
1447
|
+
const at = template.indexOf(SSR_SENTINEL);
|
|
1448
|
+
return at >= 0 ? template.slice(at + 18) : "";
|
|
1449
|
+
};
|
|
2032
1450
|
const result = {};
|
|
2033
1451
|
const nonce = prep.templateParams.nonce ?? "";
|
|
2034
1452
|
await new Promise((resolve, reject) => {
|
|
@@ -2040,6 +1458,11 @@ var streamBody = async (req, res, config, spaceId, environment, revision, render
|
|
|
2040
1458
|
cb();
|
|
2041
1459
|
},
|
|
2042
1460
|
final(cb) {
|
|
1461
|
+
const tail = tailOf(result.prePaint ? renderFn({
|
|
1462
|
+
...prep.templateParams,
|
|
1463
|
+
html: SSR_SENTINEL,
|
|
1464
|
+
prePaint: result.prePaint
|
|
1465
|
+
}) : fullTemplate);
|
|
2043
1466
|
const tailBuf = Buffer.from(tail, "utf-8");
|
|
2044
1467
|
res.write(tailBuf);
|
|
2045
1468
|
res.end();
|
|
@@ -2102,6 +1525,7 @@ var renderSSR = async (req, res, config, renderFn, pluginManager, caches, publis
|
|
|
2102
1525
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
2103
1526
|
res.setHeader("Accept-CH", SCHEME_HINT_HEADER);
|
|
2104
1527
|
res.setHeader("Vary", SCHEME_HINT_HEADER);
|
|
1528
|
+
if (req.ctx.spaceDeployment?.noindex) res.setHeader("X-Robots-Tag", "noindex, nofollow");
|
|
2105
1529
|
const hint = pageHints(config, res);
|
|
2106
1530
|
const draft = await takeDraftOverride(req, config);
|
|
2107
1531
|
const offlineDataOverride = draft?.data;
|
|
@@ -2854,7 +2278,7 @@ var buildPagePipeline = (services, extensions = {}, engine) => {
|
|
|
2854
2278
|
* pipeline. Which services it mounts is the CALLER's decision — {@link createServer} passes whatever the config
|
|
2855
2279
|
* enables — so this unit never second-guesses a factory's promise. */
|
|
2856
2280
|
var createPageServer = (config, services, extensions, engine) => {
|
|
2857
|
-
const { cacheTtlMs: htmlTtlMs = DEFAULT_TTL_MS
|
|
2281
|
+
const { cacheTtlMs: htmlTtlMs = DEFAULT_TTL_MS.html } = config;
|
|
2858
2282
|
const logLevel = config.logLevel ?? defaultLogLevel(config.devMode);
|
|
2859
2283
|
const { logger } = config;
|
|
2860
2284
|
config.logLevel = logLevel;
|
|
@@ -2875,7 +2299,7 @@ var createPageServer = (config, services, extensions, engine) => {
|
|
|
2875
2299
|
config.renderLimit = renderLimitOf(config.renderLimit);
|
|
2876
2300
|
const caches = createServerCaches({
|
|
2877
2301
|
htmlTtlMs,
|
|
2878
|
-
rscTtlMs: config.rsc?.cacheTtlMs ?? DEFAULT_TTL_MS
|
|
2302
|
+
rscTtlMs: config.rsc?.cacheTtlMs ?? DEFAULT_TTL_MS.rsc,
|
|
2879
2303
|
htmlBytes: config.cache.maxBytes,
|
|
2880
2304
|
staleMs: config.cache.staleMs
|
|
2881
2305
|
});
|