admin.html改为内部资源调用
This commit is contained in:
parent
0fb285b045
commit
2b8cb3ca9a
@ -4,10 +4,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>API Proxy Mock 配置管理</title>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://unpkg.com/element-ui/lib/theme-chalk/index.css"
|
||||
/>
|
||||
<link rel="stylesheet" href="/assets/element-ui/index.css" />
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
@ -705,8 +702,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
|
||||
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
|
||||
<script src="/assets/vue.js"></script>
|
||||
<script src="/assets/element-ui/index.js"></script>
|
||||
<script>
|
||||
new Vue({
|
||||
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(
|
||||
clientReq: http.IncomingMessage,
|
||||
clientRes: http.ServerResponse,
|
||||
@ -744,6 +805,11 @@ export async function dispatchAdmin(
|
||||
clientReq: http.IncomingMessage,
|
||||
clientRes: http.ServerResponse,
|
||||
): Promise<boolean> {
|
||||
if (requestPath === "/assets" || requestPath.startsWith("/assets/")) {
|
||||
await handleAdminAssets(requestPath, clientReq, clientRes);
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (requestPath) {
|
||||
case "/__reload-config":
|
||||
await handleReloadConfig(clientReq, clientRes);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user