admin.html改为内部资源调用
This commit is contained in:
parent
0fb285b045
commit
2b8cb3ca9a
@ -4,10 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>API Proxy Mock 配置管理</title>
|
<title>API Proxy Mock 配置管理</title>
|
||||||
<link
|
<link rel="stylesheet" href="/assets/element-ui/index.css" />
|
||||||
rel="stylesheet"
|
|
||||||
href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"
|
|
||||||
/>
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@ -705,8 +702,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
|
<script src="/assets/vue.js"></script>
|
||||||
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
|
<script src="/assets/element-ui/index.js"></script>
|
||||||
<script>
|
<script>
|
||||||
new Vue({
|
new Vue({
|
||||||
el: "#app",
|
el: "#app",
|
||||||
|
|||||||
BIN
assets/element-ui/fonts/element-icons.ttf
Normal file
BIN
assets/element-ui/fonts/element-icons.ttf
Normal file
Binary file not shown.
BIN
assets/element-ui/fonts/element-icons.woff
Normal file
BIN
assets/element-ui/fonts/element-icons.woff
Normal file
Binary file not shown.
1
assets/element-ui/index.css
Normal file
1
assets/element-ui/index.css
Normal file
File diff suppressed because one or more lines are too long
1
assets/element-ui/index.js
Normal file
1
assets/element-ui/index.js
Normal file
File diff suppressed because one or more lines are too long
11932
assets/vue.js
Normal file
11932
assets/vue.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -716,6 +716,67 @@ async function handleClientIp(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ASSETS_ROOT = path.join(__dirname, "..", "assets");
|
||||||
|
|
||||||
|
const ASSET_CONTENT_TYPES: Record<string, string> = {
|
||||||
|
".css": "text/css; charset=utf-8",
|
||||||
|
".js": "application/javascript; charset=utf-8",
|
||||||
|
".woff": "font/woff",
|
||||||
|
".ttf": "font/ttf",
|
||||||
|
".map": "application/json",
|
||||||
|
};
|
||||||
|
|
||||||
|
async function handleAdminAssets(
|
||||||
|
requestPath: string,
|
||||||
|
clientReq: http.IncomingMessage,
|
||||||
|
clientRes: http.ServerResponse,
|
||||||
|
): Promise<void> {
|
||||||
|
if (clientReq.method !== "GET" && clientReq.method !== "HEAD") {
|
||||||
|
clientRes.writeHead(405, { "Content-Type": "text/plain; charset=utf-8" });
|
||||||
|
clientRes.end("Method Not Allowed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const relativePath = decodeURIComponent(requestPath.slice("/assets/".length));
|
||||||
|
if (!relativePath || relativePath.includes("\0")) {
|
||||||
|
clientRes.writeHead(400, { "Content-Type": "text/plain; charset=utf-8" });
|
||||||
|
clientRes.end("Bad Request");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const resolved = path.resolve(ASSETS_ROOT, relativePath);
|
||||||
|
const assetsRootResolved = path.resolve(ASSETS_ROOT);
|
||||||
|
if (
|
||||||
|
resolved !== assetsRootResolved &&
|
||||||
|
!resolved.startsWith(assetsRootResolved + path.sep)
|
||||||
|
) {
|
||||||
|
clientRes.writeHead(403, { "Content-Type": "text/plain; charset=utf-8" });
|
||||||
|
clientRes.end("Forbidden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isFile()) {
|
||||||
|
clientRes.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
|
||||||
|
clientRes.end("Not Found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ext = path.extname(resolved).toLowerCase();
|
||||||
|
const contentType =
|
||||||
|
ASSET_CONTENT_TYPES[ext] || "application/octet-stream";
|
||||||
|
const body = fs.readFileSync(resolved);
|
||||||
|
clientRes.writeHead(200, {
|
||||||
|
"Content-Type": contentType,
|
||||||
|
"Content-Length": body.length,
|
||||||
|
"Cache-Control": "public, max-age=86400",
|
||||||
|
});
|
||||||
|
if (clientReq.method === "HEAD") {
|
||||||
|
clientRes.end();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
clientRes.end(body);
|
||||||
|
}
|
||||||
|
|
||||||
async function handleAdminPage(
|
async function handleAdminPage(
|
||||||
clientReq: http.IncomingMessage,
|
clientReq: http.IncomingMessage,
|
||||||
clientRes: http.ServerResponse,
|
clientRes: http.ServerResponse,
|
||||||
@ -744,6 +805,11 @@ export async function dispatchAdmin(
|
|||||||
clientReq: http.IncomingMessage,
|
clientReq: http.IncomingMessage,
|
||||||
clientRes: http.ServerResponse,
|
clientRes: http.ServerResponse,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
|
if (requestPath === "/assets" || requestPath.startsWith("/assets/")) {
|
||||||
|
await handleAdminAssets(requestPath, clientReq, clientRes);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
switch (requestPath) {
|
switch (requestPath) {
|
||||||
case "/__reload-config":
|
case "/__reload-config":
|
||||||
await handleReloadConfig(clientReq, clientRes);
|
await handleReloadConfig(clientReq, clientRes);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user