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] &&
|
||||||
g.code_index_cache[site_id][build_path].content &&
|
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] &&
|
||||||
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(
|
return new Response(
|
||||||
g.code_index_cache[site_id][build_path].content,
|
g.code_index_cache[site_id][build_path].content,
|
||||||
|
|
@ -174,7 +175,11 @@ export const _ = {
|
||||||
case "route": {
|
case "route": {
|
||||||
if (!g.route_cache) g.route_cache = {};
|
if (!g.route_cache) g.route_cache = {};
|
||||||
if (g.route_cache[site_id]) {
|
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: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
"content-encoding": "br",
|
"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({
|
const site = await _db.site.findFirst({
|
||||||
where: { id: site_id },
|
where: { id: site_id },
|
||||||
select: {
|
select: {
|
||||||
|
|
@ -227,6 +245,10 @@ export const _ = {
|
||||||
select: { url: true, id: true },
|
select: { url: true, id: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!g.route_cache[site_id]) {
|
||||||
|
g.route_cache[site_id] = {};
|
||||||
|
}
|
||||||
|
|
||||||
const res = JSON.stringify({
|
const res = JSON.stringify({
|
||||||
site: { ...site, api_url },
|
site: { ...site, api_url },
|
||||||
urls,
|
urls,
|
||||||
|
|
@ -243,11 +265,13 @@ export const _ = {
|
||||||
g.route_cache_compressing = new Set();
|
g.route_cache_compressing = new Set();
|
||||||
if (g.route_cache_compressing.has(site_id)) return;
|
if (g.route_cache_compressing.has(site_id)) return;
|
||||||
g.route_cache_compressing.add(site_id);
|
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);
|
g.route_cache_compressing.delete(site_id);
|
||||||
}, 100);
|
}, 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: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
"content-encoding": "gzip",
|
"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, {
|
return new Response(g.main_cache[src_path].content, {
|
||||||
headers: {
|
headers: {
|
||||||
"content-encoding": "br",
|
"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;
|
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 { WSData } from "../../../../../../pkgs/core/server/create";
|
||||||
import { prodIndex } from "../../../../util/prod-index";
|
import { prodIndex } from "../../../../util/prod-index";
|
||||||
|
|
||||||
import { realpathSync } from 'fs'
|
import { realpathSync } from 'fs';
|
||||||
import { code } from "../../code/code";
|
import { code } from "../../code/code";
|
||||||
import "./server-runtime";
|
|
||||||
import { initServer } from "../../code/parts/init/server";
|
import { initServer } from "../../code/parts/init/server";
|
||||||
import { waitUntil } from "web-utils";
|
import "./server-runtime";
|
||||||
|
|
||||||
if (!g.server_main_handler) {
|
if (!g.server_main_handler) {
|
||||||
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 baseUrl = (url: string) => {
|
||||||
const base = new URL(url);
|
const base = new URL(url);
|
||||||
|
|
||||||
if (!["prasi.avolut.com", "localhost"].includes(base.hostname)) {
|
// if (!["prasi.avolut.com", "localhost"].includes(base.hostname)) {
|
||||||
const cur = new URL(location.href);
|
// const cur = new URL(location.href);
|
||||||
if (!["prasi.avolut.com", "localhost"].includes(cur.hostname)) {
|
// if (!["prasi.avolut.com", "localhost"].includes(cur.hostname)) {
|
||||||
base.hostname = cur.hostname;
|
// base.hostname = cur.hostname;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return `${base.protocol}//${base.host}`;
|
return `${base.protocol}//${base.host}`;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ export const fetchSendDb = async (params: any, dburl: string) => {
|
||||||
cachedQueryResult[hsum].result = result;
|
cachedQueryResult[hsum].result = result;
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} 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 {
|
try {
|
||||||
return JSON.parse(result);
|
return JSON.parse(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("DBQuery failed:" + result);
|
console.error("DBQuery failed:", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,16 @@ const injectSiteScript = () => {
|
||||||
|
|
||||||
const ts = localStorage.getItem("api-ts-" + base_url);
|
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}`;
|
script.src = `${base_url}/_prasi/load.js?url=${base_url}&v3&ts=${ts}`;
|
||||||
|
}
|
||||||
|
|
||||||
if (!document.querySelector(`script[src="${script.src}"]`)) {
|
if (!document.querySelector(`script[src="${script.src}"]`)) {
|
||||||
d.body.appendChild(script);
|
d.body.appendChild(script);
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ export const g = global as unknown as {
|
||||||
syncronize: typeof syncronize;
|
syncronize: typeof syncronize;
|
||||||
static_cache: any;
|
static_cache: any;
|
||||||
route_cache_compressing: Set<string>;
|
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_compressing: Set<string>;
|
||||||
code_index_cache: Record<
|
code_index_cache: Record<
|
||||||
string,
|
string,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue