fix
This commit is contained in:
parent
de7acde842
commit
503baa6a64
|
|
@ -100,7 +100,8 @@ export const _ = {
|
|||
g.code_index_cache[site_id][build_path] &&
|
||||
g.code_index_cache[site_id][build_path].content &&
|
||||
g.code_index_cache[site_id][build_path] &&
|
||||
g.code_index_cache[site_id][build_path].ts === ts
|
||||
g.code_index_cache[site_id][build_path].ts === ts &&
|
||||
req.headers.get("accept-encoding")?.includes("br")
|
||||
) {
|
||||
return new Response(
|
||||
g.code_index_cache[site_id][build_path].content,
|
||||
|
|
@ -174,7 +175,11 @@ export const _ = {
|
|||
case "route": {
|
||||
if (!g.route_cache) g.route_cache = {};
|
||||
if (g.route_cache[site_id]) {
|
||||
return new Response(g.route_cache[site_id], {
|
||||
if (
|
||||
req.headers.get("accept-encoding")?.includes("br") &&
|
||||
g.route_cache[site_id].br
|
||||
) {
|
||||
return new Response(g.route_cache[site_id].br, {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"content-encoding": "br",
|
||||
|
|
@ -182,6 +187,19 @@ export const _ = {
|
|||
});
|
||||
}
|
||||
|
||||
if (
|
||||
req.headers.get("accept-encoding")?.includes("gzip") &&
|
||||
g.route_cache[site_id].gzip
|
||||
) {
|
||||
return new Response(g.route_cache[site_id].gzip, {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"content-encoding": "gzip",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const site = await _db.site.findFirst({
|
||||
where: { id: site_id },
|
||||
select: {
|
||||
|
|
@ -227,6 +245,10 @@ export const _ = {
|
|||
select: { url: true, id: true },
|
||||
});
|
||||
|
||||
if (!g.route_cache[site_id]) {
|
||||
g.route_cache[site_id] = {};
|
||||
}
|
||||
|
||||
const res = JSON.stringify({
|
||||
site: { ...site, api_url },
|
||||
urls,
|
||||
|
|
@ -243,11 +265,13 @@ export const _ = {
|
|||
g.route_cache_compressing = new Set();
|
||||
if (g.route_cache_compressing.has(site_id)) return;
|
||||
g.route_cache_compressing.add(site_id);
|
||||
g.route_cache[site_id] = g.br.compress(encoder.encode(res));
|
||||
g.route_cache[site_id].br = g.br.compress(encoder.encode(res));
|
||||
g.route_cache_compressing.delete(site_id);
|
||||
}, 100);
|
||||
|
||||
return new Response(await gzipAsync(res), {
|
||||
g.route_cache[site_id].gzip = await gzipAsync(res);
|
||||
|
||||
return new Response(g.route_cache[site_id].gzip, {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"content-encoding": "gzip",
|
||||
|
|
@ -333,7 +357,11 @@ export const _ = {
|
|||
};
|
||||
}
|
||||
}
|
||||
if (g.main_cache[src_path]) {
|
||||
|
||||
if (
|
||||
req.headers.get("accept-encoding")?.includes("br") &&
|
||||
g.main_cache[src_path]
|
||||
) {
|
||||
return new Response(g.main_cache[src_path].content, {
|
||||
headers: {
|
||||
"content-encoding": "br",
|
||||
|
|
@ -341,6 +369,20 @@ export const _ = {
|
|||
},
|
||||
});
|
||||
}
|
||||
if (req.headers.get("accept-encoding")?.includes("gzip")) {
|
||||
const file = Bun.file(src_path);
|
||||
|
||||
return new Response(
|
||||
await gzipAsync(new Uint8Array(await file.arrayBuffer())),
|
||||
{
|
||||
headers: {
|
||||
"content-encoding": "gzip",
|
||||
"content-type": mime.getType(src_path) || "",
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return index_html;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -5,11 +5,10 @@ import { g } from "utils/global";
|
|||
import { WSData } from "../../../../../../pkgs/core/server/create";
|
||||
import { prodIndex } from "../../../../util/prod-index";
|
||||
|
||||
import { realpathSync } from 'fs'
|
||||
import { realpathSync } from 'fs';
|
||||
import { code } from "../../code/code";
|
||||
import "./server-runtime";
|
||||
import { initServer } from "../../code/parts/init/server";
|
||||
import { waitUntil } from "web-utils";
|
||||
import "./server-runtime";
|
||||
|
||||
if (!g.server_main_handler) {
|
||||
g.server_main_handler = {};
|
||||
|
|
|
|||
|
|
@ -62,12 +62,12 @@ export const loadApiProxyDef = async (_url: string, with_types: boolean) => {
|
|||
const baseUrl = (url: string) => {
|
||||
const base = new URL(url);
|
||||
|
||||
if (!["prasi.avolut.com", "localhost"].includes(base.hostname)) {
|
||||
const cur = new URL(location.href);
|
||||
if (!["prasi.avolut.com", "localhost"].includes(cur.hostname)) {
|
||||
base.hostname = cur.hostname;
|
||||
}
|
||||
}
|
||||
// if (!["prasi.avolut.com", "localhost"].includes(base.hostname)) {
|
||||
// const cur = new URL(location.href);
|
||||
// if (!["prasi.avolut.com", "localhost"].includes(cur.hostname)) {
|
||||
// base.hostname = cur.hostname;
|
||||
// }
|
||||
// }
|
||||
|
||||
return `${base.protocol}//${base.host}`;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ export const fetchSendDb = async (params: any, dburl: string) => {
|
|||
cachedQueryResult[hsum].result = result;
|
||||
return result;
|
||||
} catch (e) {
|
||||
console.error("DBQuery failed:" + result);
|
||||
console.error("DBQuery failed:", result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ export const fetchSendDb = async (params: any, dburl: string) => {
|
|||
try {
|
||||
return JSON.parse(result);
|
||||
} catch (e) {
|
||||
console.error("DBQuery failed:" + result);
|
||||
console.error("DBQuery failed:", result);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -93,7 +93,16 @@ const injectSiteScript = () => {
|
|||
|
||||
const ts = localStorage.getItem("api-ts-" + base_url);
|
||||
|
||||
const cur = new URL(location.href);
|
||||
cur.pathname = "";
|
||||
if (!["prasi.avolut.com", "localhost"].includes(cur.hostname)) {
|
||||
const cur_url = cur.toString();
|
||||
script.src = `${
|
||||
cur_url.endsWith("/") ? cur_url : `${cur_url}/`
|
||||
}_prasi/load.js?url=${cur_url}&v3&ts=${ts}`;
|
||||
} else {
|
||||
script.src = `${base_url}/_prasi/load.js?url=${base_url}&v3&ts=${ts}`;
|
||||
}
|
||||
|
||||
if (!document.querySelector(`script[src="${script.src}"]`)) {
|
||||
d.body.appendChild(script);
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ export const g = global as unknown as {
|
|||
syncronize: typeof syncronize;
|
||||
static_cache: any;
|
||||
route_cache_compressing: Set<string>;
|
||||
route_cache: Record<string, any>;
|
||||
route_cache: Record<string, {br?: any, gzip?: any}>;
|
||||
code_index_compressing: Set<string>;
|
||||
code_index_cache: Record<
|
||||
string,
|
||||
|
|
|
|||
Loading…
Reference in New Issue