fix
This commit is contained in:
parent
58ce3642bb
commit
6b5b8526ee
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,4 @@
|
|||
import trim from "lodash.trim";
|
||||
import { w } from "../../../utils/types/general";
|
||||
import { fetchViaProxy } from "../proxy";
|
||||
|
||||
export const loadApiProxyDef = async (_url: string, with_types: boolean) => {
|
||||
const url = trim(_url, "/");
|
||||
|
|
@ -20,10 +18,18 @@ export const loadApiProxyDef = async (_url: string, with_types: boolean) => {
|
|||
|
||||
const ts = localStorage.getItem("api-ts-" + url);
|
||||
|
||||
const url_target = new URL(url);
|
||||
const url_cur = new URL(location.href);
|
||||
|
||||
let is_remote = "";
|
||||
if (url_target.host !== url_cur.host) {
|
||||
is_remote = "&remote=1";
|
||||
}
|
||||
|
||||
if (with_types) {
|
||||
script.src = `${base}/_prasi/load.js?url=${url}&v3&dev=1&ts=${ts}`;
|
||||
script.src = `/_prasi/load.js?url=${url}&v3&dev=1&ts=${ts}${is_remote}`;
|
||||
} else {
|
||||
script.src = `${base}/_prasi/load.js?url=${url}&v3&ts=${ts}`;
|
||||
script.src = `/_prasi/load.js?url=${url}&v3&ts=${ts}${is_remote}`;
|
||||
}
|
||||
script.onerror = () => {
|
||||
done();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ const cache = {
|
|||
|
||||
export const _ = {
|
||||
url: "/_prasi/*",
|
||||
raw: true,
|
||||
async api() {
|
||||
const { req, res } = apiContext(this);
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
|
|
@ -25,6 +26,20 @@ export const _ = {
|
|||
? JSON.stringify(req.query_parameters["url"])
|
||||
: "undefined";
|
||||
|
||||
const is_remote = req.query_parameters["remote"];
|
||||
if (is_remote) {
|
||||
const cur_url = new URL(req.url);
|
||||
const remote_url = new URL(req.query_parameters["url"]);
|
||||
cur_url.hostname = remote_url.hostname;
|
||||
cur_url.port = remote_url.port;
|
||||
cur_url.protocol = remote_url.protocol;
|
||||
const res = await (await fetch(cur_url.toString())).text();
|
||||
|
||||
return new Response(res, {
|
||||
headers: { "content-type": "text/javascript; charset=UTF-8" },
|
||||
});
|
||||
}
|
||||
|
||||
const mode = req.query_parameters["dev"] ? "dev" : "prod";
|
||||
|
||||
if (!cache[mode]) {
|
||||
|
|
@ -77,7 +92,7 @@ export const _ = {
|
|||
const run = action[pathname];
|
||||
|
||||
if (run) {
|
||||
await run();
|
||||
return await run();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue