@squadbase/vite-server 0.1.3-dev.8 → 0.1.3-dev.9
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/index.js +84 -47
- package/dist/main.js +84 -47
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39679,7 +39679,7 @@ __export(lib_exports, {
|
|
|
39679
39679
|
FetchError: () => FetchError,
|
|
39680
39680
|
Headers: () => Headers2,
|
|
39681
39681
|
Request: () => Request2,
|
|
39682
|
-
Response: () =>
|
|
39682
|
+
Response: () => Response2,
|
|
39683
39683
|
default: () => lib_default
|
|
39684
39684
|
});
|
|
39685
39685
|
import Stream from "stream";
|
|
@@ -40205,7 +40205,7 @@ function fetch2(url, opts) {
|
|
|
40205
40205
|
};
|
|
40206
40206
|
const codings = headers.get("Content-Encoding");
|
|
40207
40207
|
if (!request2.compress || request2.method === "HEAD" || codings === null || res.statusCode === 204 || res.statusCode === 304) {
|
|
40208
|
-
response = new
|
|
40208
|
+
response = new Response2(body, response_options);
|
|
40209
40209
|
resolve(response);
|
|
40210
40210
|
return;
|
|
40211
40211
|
}
|
|
@@ -40215,7 +40215,7 @@ function fetch2(url, opts) {
|
|
|
40215
40215
|
};
|
|
40216
40216
|
if (codings == "gzip" || codings == "x-gzip") {
|
|
40217
40217
|
body = body.pipe(zlib.createGunzip(zlibOptions));
|
|
40218
|
-
response = new
|
|
40218
|
+
response = new Response2(body, response_options);
|
|
40219
40219
|
resolve(response);
|
|
40220
40220
|
return;
|
|
40221
40221
|
}
|
|
@@ -40227,12 +40227,12 @@ function fetch2(url, opts) {
|
|
|
40227
40227
|
} else {
|
|
40228
40228
|
body = body.pipe(zlib.createInflateRaw());
|
|
40229
40229
|
}
|
|
40230
|
-
response = new
|
|
40230
|
+
response = new Response2(body, response_options);
|
|
40231
40231
|
resolve(response);
|
|
40232
40232
|
});
|
|
40233
40233
|
raw.on("end", function() {
|
|
40234
40234
|
if (!response) {
|
|
40235
|
-
response = new
|
|
40235
|
+
response = new Response2(body, response_options);
|
|
40236
40236
|
resolve(response);
|
|
40237
40237
|
}
|
|
40238
40238
|
});
|
|
@@ -40240,11 +40240,11 @@ function fetch2(url, opts) {
|
|
|
40240
40240
|
}
|
|
40241
40241
|
if (codings == "br" && typeof zlib.createBrotliDecompress === "function") {
|
|
40242
40242
|
body = body.pipe(zlib.createBrotliDecompress());
|
|
40243
|
-
response = new
|
|
40243
|
+
response = new Response2(body, response_options);
|
|
40244
40244
|
resolve(response);
|
|
40245
40245
|
return;
|
|
40246
40246
|
}
|
|
40247
|
-
response = new
|
|
40247
|
+
response = new Response2(body, response_options);
|
|
40248
40248
|
resolve(response);
|
|
40249
40249
|
});
|
|
40250
40250
|
writeToStream(req, request2);
|
|
@@ -40277,7 +40277,7 @@ function destroyStream(stream, err) {
|
|
|
40277
40277
|
stream.end();
|
|
40278
40278
|
}
|
|
40279
40279
|
}
|
|
40280
|
-
var import_whatwg_url, Readable6, BUFFER, TYPE, Blob2, convert, INTERNALS, PassThrough, invalidTokenRegex, invalidHeaderCharRegex, MAP, Headers2, INTERNAL, HeadersIteratorPrototype, INTERNALS$1, STATUS_CODES,
|
|
40280
|
+
var import_whatwg_url, Readable6, BUFFER, TYPE, Blob2, convert, INTERNALS, PassThrough, invalidTokenRegex, invalidHeaderCharRegex, MAP, Headers2, INTERNAL, HeadersIteratorPrototype, INTERNALS$1, STATUS_CODES, Response2, INTERNALS$2, URL2, parse_url, format_url, streamDestructionSupported, Request2, URL$1, PassThrough$1, isDomainOrSubdomain, isSameProtocol, lib_default;
|
|
40281
40281
|
var init_lib2 = __esm({
|
|
40282
40282
|
"../../node_modules/node-fetch/lib/index.mjs"() {
|
|
40283
40283
|
"use strict";
|
|
@@ -40720,7 +40720,7 @@ var init_lib2 = __esm({
|
|
|
40720
40720
|
});
|
|
40721
40721
|
INTERNALS$1 = /* @__PURE__ */ Symbol("Response internals");
|
|
40722
40722
|
STATUS_CODES = http.STATUS_CODES;
|
|
40723
|
-
|
|
40723
|
+
Response2 = class _Response {
|
|
40724
40724
|
constructor() {
|
|
40725
40725
|
let body = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
|
|
40726
40726
|
let opts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
@@ -40778,8 +40778,8 @@ var init_lib2 = __esm({
|
|
|
40778
40778
|
});
|
|
40779
40779
|
}
|
|
40780
40780
|
};
|
|
40781
|
-
Body.mixIn(
|
|
40782
|
-
Object.defineProperties(
|
|
40781
|
+
Body.mixIn(Response2.prototype);
|
|
40782
|
+
Object.defineProperties(Response2.prototype, {
|
|
40783
40783
|
url: { enumerable: true },
|
|
40784
40784
|
status: { enumerable: true },
|
|
40785
40785
|
ok: { enumerable: true },
|
|
@@ -40788,7 +40788,7 @@ var init_lib2 = __esm({
|
|
|
40788
40788
|
headers: { enumerable: true },
|
|
40789
40789
|
clone: { enumerable: true }
|
|
40790
40790
|
});
|
|
40791
|
-
Object.defineProperty(
|
|
40791
|
+
Object.defineProperty(Response2.prototype, Symbol.toStringTag, {
|
|
40792
40792
|
value: "Response",
|
|
40793
40793
|
writable: false,
|
|
40794
40794
|
enumerable: false,
|
|
@@ -86428,11 +86428,42 @@ function buildCacheKey(slug, params) {
|
|
|
86428
86428
|
|
|
86429
86429
|
// src/routes/server-logic.ts
|
|
86430
86430
|
var app = new Hono();
|
|
86431
|
-
function
|
|
86432
|
-
return c6.json({ data:
|
|
86431
|
+
function buildSqlResponseFromRows(c6, rows) {
|
|
86432
|
+
return c6.json({ data: rows });
|
|
86433
86433
|
}
|
|
86434
|
-
function
|
|
86435
|
-
return
|
|
86434
|
+
function buildTypescriptResponseFromJsonBody(jsonBody) {
|
|
86435
|
+
return Response.json(jsonBody);
|
|
86436
|
+
}
|
|
86437
|
+
function buildResponseFromCache(c6, data) {
|
|
86438
|
+
if (data.type === "sql") {
|
|
86439
|
+
return buildSqlResponseFromRows(c6, data.rows);
|
|
86440
|
+
}
|
|
86441
|
+
return buildTypescriptResponseFromJsonBody(data.jsonBody);
|
|
86442
|
+
}
|
|
86443
|
+
function isJsonContentType(response) {
|
|
86444
|
+
const header = response.headers.get("content-type") ?? "";
|
|
86445
|
+
const lower = header.toLowerCase();
|
|
86446
|
+
return lower.startsWith("application/json") || lower.includes("+json");
|
|
86447
|
+
}
|
|
86448
|
+
async function cacheTypescriptResponse(response) {
|
|
86449
|
+
if (response.status !== 200 || !isJsonContentType(response)) {
|
|
86450
|
+
return { cacheable: false, response };
|
|
86451
|
+
}
|
|
86452
|
+
const jsonBody = await response.json();
|
|
86453
|
+
return {
|
|
86454
|
+
cacheable: true,
|
|
86455
|
+
data: { type: "typescript", jsonBody },
|
|
86456
|
+
response: buildTypescriptResponseFromJsonBody(jsonBody)
|
|
86457
|
+
};
|
|
86458
|
+
}
|
|
86459
|
+
function withCacheHeaders(c6, status, ageSeconds, ttl) {
|
|
86460
|
+
c6.header("X-Cache", status);
|
|
86461
|
+
c6.header("X-Cache-Age", String(ageSeconds));
|
|
86462
|
+
if (status === "STALE") {
|
|
86463
|
+
c6.header("Cache-Control", `max-age=0, stale-while-revalidate=${ttl}`);
|
|
86464
|
+
} else {
|
|
86465
|
+
c6.header("Cache-Control", `max-age=${Math.max(0, ttl - ageSeconds)}`);
|
|
86466
|
+
}
|
|
86436
86467
|
}
|
|
86437
86468
|
app.get("/:slug", async (c6) => {
|
|
86438
86469
|
const slug = c6.req.param("slug");
|
|
@@ -86444,10 +86475,10 @@ app.get("/:slug", async (c6) => {
|
|
|
86444
86475
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
86445
86476
|
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
86446
86477
|
const result = await handler(c6);
|
|
86447
|
-
return
|
|
86478
|
+
return result;
|
|
86448
86479
|
} else {
|
|
86449
|
-
const
|
|
86450
|
-
return
|
|
86480
|
+
const rows = await ds.handler({});
|
|
86481
|
+
return buildSqlResponseFromRows(c6, rows);
|
|
86451
86482
|
}
|
|
86452
86483
|
} catch (e6) {
|
|
86453
86484
|
console.error(`[server-logic] ${slug} error:`, e6);
|
|
@@ -86471,61 +86502,67 @@ app.post("/:slug", async (c6) => {
|
|
|
86471
86502
|
if (ttl <= 0) {
|
|
86472
86503
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
86473
86504
|
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
86474
|
-
const
|
|
86475
|
-
return
|
|
86505
|
+
const result = await handler(c6);
|
|
86506
|
+
return result;
|
|
86476
86507
|
} else {
|
|
86477
|
-
const
|
|
86478
|
-
return
|
|
86508
|
+
const rows2 = await ds.handler(params);
|
|
86509
|
+
return buildSqlResponseFromRows(c6, rows2);
|
|
86479
86510
|
}
|
|
86480
86511
|
}
|
|
86481
86512
|
const cacheKey = buildCacheKey(slug, params);
|
|
86482
86513
|
const cached = cacheGet(cacheKey);
|
|
86483
|
-
const buildResponse = ds._isTypescript ? (r6) => buildTypescriptResponse(r6) : (r6) => buildSqlResponse(c6, r6);
|
|
86484
86514
|
if (cached) {
|
|
86485
86515
|
if (isFresh(cached)) {
|
|
86486
86516
|
recordHit(cacheKey);
|
|
86487
86517
|
const ageSeconds = Math.floor((Date.now() - cached.cachedAt) / 1e3);
|
|
86488
|
-
c6
|
|
86489
|
-
c6
|
|
86490
|
-
c6.header("Cache-Control", `max-age=${ttl - ageSeconds}`);
|
|
86491
|
-
return buildResponse(cached.data);
|
|
86518
|
+
withCacheHeaders(c6, "HIT", ageSeconds, ttl);
|
|
86519
|
+
return buildResponseFromCache(c6, cached.data);
|
|
86492
86520
|
}
|
|
86493
86521
|
if (cacheConfig?.staleWhileRevalidate) {
|
|
86494
86522
|
recordHit(cacheKey);
|
|
86495
86523
|
const ageSeconds = Math.floor((Date.now() - cached.cachedAt) / 1e3);
|
|
86496
|
-
c6
|
|
86497
|
-
c6.header("X-Cache-Age", String(ageSeconds));
|
|
86498
|
-
c6.header("Cache-Control", `max-age=0, stale-while-revalidate=${ttl}`);
|
|
86524
|
+
withCacheHeaders(c6, "STALE", ageSeconds, ttl);
|
|
86499
86525
|
void (async () => {
|
|
86500
86526
|
try {
|
|
86501
|
-
let freshData;
|
|
86502
86527
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
86503
86528
|
const tsHandler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
86504
|
-
|
|
86529
|
+
const freshResponse = await tsHandler(c6);
|
|
86530
|
+
const outcome = await cacheTypescriptResponse(freshResponse);
|
|
86531
|
+
if (outcome.cacheable) {
|
|
86532
|
+
cacheSet(cacheKey, outcome.data, ttl);
|
|
86533
|
+
console.log(`[cache] background revalidated: ${cacheKey}`);
|
|
86534
|
+
} else {
|
|
86535
|
+
console.log(
|
|
86536
|
+
`[cache] background revalidation skipped (non-cacheable response) for ${cacheKey}`
|
|
86537
|
+
);
|
|
86538
|
+
}
|
|
86505
86539
|
} else {
|
|
86506
|
-
|
|
86540
|
+
const rows2 = await ds.handler(params);
|
|
86541
|
+
cacheSet(cacheKey, { type: "sql", rows: rows2 }, ttl);
|
|
86542
|
+
console.log(`[cache] background revalidated: ${cacheKey}`);
|
|
86507
86543
|
}
|
|
86508
|
-
cacheSet(cacheKey, freshData, ttl);
|
|
86509
|
-
console.log(`[cache] background revalidated: ${cacheKey}`);
|
|
86510
86544
|
} catch (e6) {
|
|
86511
86545
|
console.error(`[cache] background revalidation failed for ${slug}:`, e6);
|
|
86512
86546
|
}
|
|
86513
86547
|
})();
|
|
86514
|
-
return
|
|
86548
|
+
return buildResponseFromCache(c6, cached.data);
|
|
86515
86549
|
}
|
|
86516
86550
|
}
|
|
86517
|
-
let result;
|
|
86518
86551
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
86519
86552
|
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
86520
|
-
|
|
86521
|
-
|
|
86522
|
-
|
|
86523
|
-
|
|
86524
|
-
|
|
86525
|
-
|
|
86526
|
-
|
|
86527
|
-
|
|
86528
|
-
|
|
86553
|
+
const response = await handler(c6);
|
|
86554
|
+
const outcome = await cacheTypescriptResponse(response);
|
|
86555
|
+
if (outcome.cacheable) {
|
|
86556
|
+
cacheSet(cacheKey, outcome.data, ttl);
|
|
86557
|
+
withCacheHeaders(c6, "MISS", 0, ttl);
|
|
86558
|
+
return outcome.response;
|
|
86559
|
+
}
|
|
86560
|
+
return outcome.response;
|
|
86561
|
+
}
|
|
86562
|
+
const rows = await ds.handler(params);
|
|
86563
|
+
cacheSet(cacheKey, { type: "sql", rows }, ttl);
|
|
86564
|
+
withCacheHeaders(c6, "MISS", 0, ttl);
|
|
86565
|
+
return buildSqlResponseFromRows(c6, rows);
|
|
86529
86566
|
} catch (e6) {
|
|
86530
86567
|
console.error(`[server-logic] ${slug} error:`, e6);
|
|
86531
86568
|
return c6.json(
|
package/dist/main.js
CHANGED
|
@@ -39679,7 +39679,7 @@ __export(lib_exports, {
|
|
|
39679
39679
|
FetchError: () => FetchError,
|
|
39680
39680
|
Headers: () => Headers2,
|
|
39681
39681
|
Request: () => Request2,
|
|
39682
|
-
Response: () =>
|
|
39682
|
+
Response: () => Response2,
|
|
39683
39683
|
default: () => lib_default
|
|
39684
39684
|
});
|
|
39685
39685
|
import Stream from "stream";
|
|
@@ -40205,7 +40205,7 @@ function fetch2(url, opts) {
|
|
|
40205
40205
|
};
|
|
40206
40206
|
const codings = headers.get("Content-Encoding");
|
|
40207
40207
|
if (!request2.compress || request2.method === "HEAD" || codings === null || res.statusCode === 204 || res.statusCode === 304) {
|
|
40208
|
-
response = new
|
|
40208
|
+
response = new Response2(body, response_options);
|
|
40209
40209
|
resolve(response);
|
|
40210
40210
|
return;
|
|
40211
40211
|
}
|
|
@@ -40215,7 +40215,7 @@ function fetch2(url, opts) {
|
|
|
40215
40215
|
};
|
|
40216
40216
|
if (codings == "gzip" || codings == "x-gzip") {
|
|
40217
40217
|
body = body.pipe(zlib.createGunzip(zlibOptions));
|
|
40218
|
-
response = new
|
|
40218
|
+
response = new Response2(body, response_options);
|
|
40219
40219
|
resolve(response);
|
|
40220
40220
|
return;
|
|
40221
40221
|
}
|
|
@@ -40227,12 +40227,12 @@ function fetch2(url, opts) {
|
|
|
40227
40227
|
} else {
|
|
40228
40228
|
body = body.pipe(zlib.createInflateRaw());
|
|
40229
40229
|
}
|
|
40230
|
-
response = new
|
|
40230
|
+
response = new Response2(body, response_options);
|
|
40231
40231
|
resolve(response);
|
|
40232
40232
|
});
|
|
40233
40233
|
raw.on("end", function() {
|
|
40234
40234
|
if (!response) {
|
|
40235
|
-
response = new
|
|
40235
|
+
response = new Response2(body, response_options);
|
|
40236
40236
|
resolve(response);
|
|
40237
40237
|
}
|
|
40238
40238
|
});
|
|
@@ -40240,11 +40240,11 @@ function fetch2(url, opts) {
|
|
|
40240
40240
|
}
|
|
40241
40241
|
if (codings == "br" && typeof zlib.createBrotliDecompress === "function") {
|
|
40242
40242
|
body = body.pipe(zlib.createBrotliDecompress());
|
|
40243
|
-
response = new
|
|
40243
|
+
response = new Response2(body, response_options);
|
|
40244
40244
|
resolve(response);
|
|
40245
40245
|
return;
|
|
40246
40246
|
}
|
|
40247
|
-
response = new
|
|
40247
|
+
response = new Response2(body, response_options);
|
|
40248
40248
|
resolve(response);
|
|
40249
40249
|
});
|
|
40250
40250
|
writeToStream(req, request2);
|
|
@@ -40277,7 +40277,7 @@ function destroyStream(stream, err) {
|
|
|
40277
40277
|
stream.end();
|
|
40278
40278
|
}
|
|
40279
40279
|
}
|
|
40280
|
-
var import_whatwg_url, Readable6, BUFFER, TYPE, Blob2, convert, INTERNALS, PassThrough, invalidTokenRegex, invalidHeaderCharRegex, MAP, Headers2, INTERNAL, HeadersIteratorPrototype, INTERNALS$1, STATUS_CODES,
|
|
40280
|
+
var import_whatwg_url, Readable6, BUFFER, TYPE, Blob2, convert, INTERNALS, PassThrough, invalidTokenRegex, invalidHeaderCharRegex, MAP, Headers2, INTERNAL, HeadersIteratorPrototype, INTERNALS$1, STATUS_CODES, Response2, INTERNALS$2, URL2, parse_url, format_url, streamDestructionSupported, Request2, URL$1, PassThrough$1, isDomainOrSubdomain, isSameProtocol, lib_default;
|
|
40281
40281
|
var init_lib2 = __esm({
|
|
40282
40282
|
"../../node_modules/node-fetch/lib/index.mjs"() {
|
|
40283
40283
|
"use strict";
|
|
@@ -40720,7 +40720,7 @@ var init_lib2 = __esm({
|
|
|
40720
40720
|
});
|
|
40721
40721
|
INTERNALS$1 = /* @__PURE__ */ Symbol("Response internals");
|
|
40722
40722
|
STATUS_CODES = http.STATUS_CODES;
|
|
40723
|
-
|
|
40723
|
+
Response2 = class _Response {
|
|
40724
40724
|
constructor() {
|
|
40725
40725
|
let body = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
|
|
40726
40726
|
let opts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
@@ -40778,8 +40778,8 @@ var init_lib2 = __esm({
|
|
|
40778
40778
|
});
|
|
40779
40779
|
}
|
|
40780
40780
|
};
|
|
40781
|
-
Body.mixIn(
|
|
40782
|
-
Object.defineProperties(
|
|
40781
|
+
Body.mixIn(Response2.prototype);
|
|
40782
|
+
Object.defineProperties(Response2.prototype, {
|
|
40783
40783
|
url: { enumerable: true },
|
|
40784
40784
|
status: { enumerable: true },
|
|
40785
40785
|
ok: { enumerable: true },
|
|
@@ -40788,7 +40788,7 @@ var init_lib2 = __esm({
|
|
|
40788
40788
|
headers: { enumerable: true },
|
|
40789
40789
|
clone: { enumerable: true }
|
|
40790
40790
|
});
|
|
40791
|
-
Object.defineProperty(
|
|
40791
|
+
Object.defineProperty(Response2.prototype, Symbol.toStringTag, {
|
|
40792
40792
|
value: "Response",
|
|
40793
40793
|
writable: false,
|
|
40794
40794
|
enumerable: false,
|
|
@@ -86167,11 +86167,42 @@ function buildCacheKey(slug, params) {
|
|
|
86167
86167
|
|
|
86168
86168
|
// src/routes/server-logic.ts
|
|
86169
86169
|
var app = new Hono();
|
|
86170
|
-
function
|
|
86171
|
-
return c6.json({ data:
|
|
86170
|
+
function buildSqlResponseFromRows(c6, rows) {
|
|
86171
|
+
return c6.json({ data: rows });
|
|
86172
86172
|
}
|
|
86173
|
-
function
|
|
86174
|
-
return
|
|
86173
|
+
function buildTypescriptResponseFromJsonBody(jsonBody) {
|
|
86174
|
+
return Response.json(jsonBody);
|
|
86175
|
+
}
|
|
86176
|
+
function buildResponseFromCache(c6, data) {
|
|
86177
|
+
if (data.type === "sql") {
|
|
86178
|
+
return buildSqlResponseFromRows(c6, data.rows);
|
|
86179
|
+
}
|
|
86180
|
+
return buildTypescriptResponseFromJsonBody(data.jsonBody);
|
|
86181
|
+
}
|
|
86182
|
+
function isJsonContentType(response) {
|
|
86183
|
+
const header = response.headers.get("content-type") ?? "";
|
|
86184
|
+
const lower = header.toLowerCase();
|
|
86185
|
+
return lower.startsWith("application/json") || lower.includes("+json");
|
|
86186
|
+
}
|
|
86187
|
+
async function cacheTypescriptResponse(response) {
|
|
86188
|
+
if (response.status !== 200 || !isJsonContentType(response)) {
|
|
86189
|
+
return { cacheable: false, response };
|
|
86190
|
+
}
|
|
86191
|
+
const jsonBody = await response.json();
|
|
86192
|
+
return {
|
|
86193
|
+
cacheable: true,
|
|
86194
|
+
data: { type: "typescript", jsonBody },
|
|
86195
|
+
response: buildTypescriptResponseFromJsonBody(jsonBody)
|
|
86196
|
+
};
|
|
86197
|
+
}
|
|
86198
|
+
function withCacheHeaders(c6, status, ageSeconds, ttl) {
|
|
86199
|
+
c6.header("X-Cache", status);
|
|
86200
|
+
c6.header("X-Cache-Age", String(ageSeconds));
|
|
86201
|
+
if (status === "STALE") {
|
|
86202
|
+
c6.header("Cache-Control", `max-age=0, stale-while-revalidate=${ttl}`);
|
|
86203
|
+
} else {
|
|
86204
|
+
c6.header("Cache-Control", `max-age=${Math.max(0, ttl - ageSeconds)}`);
|
|
86205
|
+
}
|
|
86175
86206
|
}
|
|
86176
86207
|
app.get("/:slug", async (c6) => {
|
|
86177
86208
|
const slug = c6.req.param("slug");
|
|
@@ -86183,10 +86214,10 @@ app.get("/:slug", async (c6) => {
|
|
|
86183
86214
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
86184
86215
|
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
86185
86216
|
const result = await handler(c6);
|
|
86186
|
-
return
|
|
86217
|
+
return result;
|
|
86187
86218
|
} else {
|
|
86188
|
-
const
|
|
86189
|
-
return
|
|
86219
|
+
const rows = await ds.handler({});
|
|
86220
|
+
return buildSqlResponseFromRows(c6, rows);
|
|
86190
86221
|
}
|
|
86191
86222
|
} catch (e6) {
|
|
86192
86223
|
console.error(`[server-logic] ${slug} error:`, e6);
|
|
@@ -86210,61 +86241,67 @@ app.post("/:slug", async (c6) => {
|
|
|
86210
86241
|
if (ttl <= 0) {
|
|
86211
86242
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
86212
86243
|
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
86213
|
-
const
|
|
86214
|
-
return
|
|
86244
|
+
const result = await handler(c6);
|
|
86245
|
+
return result;
|
|
86215
86246
|
} else {
|
|
86216
|
-
const
|
|
86217
|
-
return
|
|
86247
|
+
const rows2 = await ds.handler(params);
|
|
86248
|
+
return buildSqlResponseFromRows(c6, rows2);
|
|
86218
86249
|
}
|
|
86219
86250
|
}
|
|
86220
86251
|
const cacheKey = buildCacheKey(slug, params);
|
|
86221
86252
|
const cached = cacheGet(cacheKey);
|
|
86222
|
-
const buildResponse = ds._isTypescript ? (r6) => buildTypescriptResponse(r6) : (r6) => buildSqlResponse(c6, r6);
|
|
86223
86253
|
if (cached) {
|
|
86224
86254
|
if (isFresh(cached)) {
|
|
86225
86255
|
recordHit(cacheKey);
|
|
86226
86256
|
const ageSeconds = Math.floor((Date.now() - cached.cachedAt) / 1e3);
|
|
86227
|
-
c6
|
|
86228
|
-
c6
|
|
86229
|
-
c6.header("Cache-Control", `max-age=${ttl - ageSeconds}`);
|
|
86230
|
-
return buildResponse(cached.data);
|
|
86257
|
+
withCacheHeaders(c6, "HIT", ageSeconds, ttl);
|
|
86258
|
+
return buildResponseFromCache(c6, cached.data);
|
|
86231
86259
|
}
|
|
86232
86260
|
if (cacheConfig?.staleWhileRevalidate) {
|
|
86233
86261
|
recordHit(cacheKey);
|
|
86234
86262
|
const ageSeconds = Math.floor((Date.now() - cached.cachedAt) / 1e3);
|
|
86235
|
-
c6
|
|
86236
|
-
c6.header("X-Cache-Age", String(ageSeconds));
|
|
86237
|
-
c6.header("Cache-Control", `max-age=0, stale-while-revalidate=${ttl}`);
|
|
86263
|
+
withCacheHeaders(c6, "STALE", ageSeconds, ttl);
|
|
86238
86264
|
void (async () => {
|
|
86239
86265
|
try {
|
|
86240
|
-
let freshData;
|
|
86241
86266
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
86242
86267
|
const tsHandler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
86243
|
-
|
|
86268
|
+
const freshResponse = await tsHandler(c6);
|
|
86269
|
+
const outcome = await cacheTypescriptResponse(freshResponse);
|
|
86270
|
+
if (outcome.cacheable) {
|
|
86271
|
+
cacheSet(cacheKey, outcome.data, ttl);
|
|
86272
|
+
console.log(`[cache] background revalidated: ${cacheKey}`);
|
|
86273
|
+
} else {
|
|
86274
|
+
console.log(
|
|
86275
|
+
`[cache] background revalidation skipped (non-cacheable response) for ${cacheKey}`
|
|
86276
|
+
);
|
|
86277
|
+
}
|
|
86244
86278
|
} else {
|
|
86245
|
-
|
|
86279
|
+
const rows2 = await ds.handler(params);
|
|
86280
|
+
cacheSet(cacheKey, { type: "sql", rows: rows2 }, ttl);
|
|
86281
|
+
console.log(`[cache] background revalidated: ${cacheKey}`);
|
|
86246
86282
|
}
|
|
86247
|
-
cacheSet(cacheKey, freshData, ttl);
|
|
86248
|
-
console.log(`[cache] background revalidated: ${cacheKey}`);
|
|
86249
86283
|
} catch (e6) {
|
|
86250
86284
|
console.error(`[cache] background revalidation failed for ${slug}:`, e6);
|
|
86251
86285
|
}
|
|
86252
86286
|
})();
|
|
86253
|
-
return
|
|
86287
|
+
return buildResponseFromCache(c6, cached.data);
|
|
86254
86288
|
}
|
|
86255
86289
|
}
|
|
86256
|
-
let result;
|
|
86257
86290
|
if (ds._isTypescript && ds._tsHandlerPath) {
|
|
86258
86291
|
const handler = await loadTypeScriptHandler(ds._tsHandlerPath);
|
|
86259
|
-
|
|
86260
|
-
|
|
86261
|
-
|
|
86262
|
-
|
|
86263
|
-
|
|
86264
|
-
|
|
86265
|
-
|
|
86266
|
-
|
|
86267
|
-
|
|
86292
|
+
const response = await handler(c6);
|
|
86293
|
+
const outcome = await cacheTypescriptResponse(response);
|
|
86294
|
+
if (outcome.cacheable) {
|
|
86295
|
+
cacheSet(cacheKey, outcome.data, ttl);
|
|
86296
|
+
withCacheHeaders(c6, "MISS", 0, ttl);
|
|
86297
|
+
return outcome.response;
|
|
86298
|
+
}
|
|
86299
|
+
return outcome.response;
|
|
86300
|
+
}
|
|
86301
|
+
const rows = await ds.handler(params);
|
|
86302
|
+
cacheSet(cacheKey, { type: "sql", rows }, ttl);
|
|
86303
|
+
withCacheHeaders(c6, "MISS", 0, ttl);
|
|
86304
|
+
return buildSqlResponseFromRows(c6, rows);
|
|
86268
86305
|
} catch (e6) {
|
|
86269
86306
|
console.error(`[server-logic] ${slug} error:`, e6);
|
|
86270
86307
|
return c6.json(
|