This commit is contained in:
2026-04-18 13:05:29 +08:00
parent 09d4c0c31b
commit 5032701c38
77 changed files with 8538 additions and 2413 deletions

View File

@@ -20,6 +20,7 @@ const runtimeNodePath = fs.existsSync(bundledNodePath)
: process.execPath;
const serverBuildPath = path.join(repoRoot, 'server-node', 'dist', 'server.js');
const webBuildPath = path.join(repoRoot, 'dist', 'index.html');
const publicRoot = path.join(repoRoot, 'public');
const proxyPort = 18080;
const nodePort = 18081;
const proxyBaseUrl = `http://127.0.0.1:${proxyPort}`;
@@ -130,6 +131,18 @@ function contentTypeFor(filePath: string) {
if (filePath.endsWith('.json')) {
return 'application/json; charset=utf-8';
}
if (filePath.endsWith('.png')) {
return 'image/png';
}
if (filePath.endsWith('.jpg') || filePath.endsWith('.jpeg')) {
return 'image/jpeg';
}
if (filePath.endsWith('.webp')) {
return 'image/webp';
}
if (filePath.endsWith('.svg')) {
return 'image/svg+xml; charset=utf-8';
}
return 'application/octet-stream';
}
@@ -138,15 +151,24 @@ function resolveStaticFile(urlPath: string) {
const cleanPath = decodeURIComponent(urlPath.split('?')[0] || '/');
const normalizedPath = cleanPath === '/' ? '/index.html' : cleanPath;
const trimmedRelativePath = normalizedPath.replace(/^\/+/u, '');
const candidatePath = path.resolve(repoRoot, 'dist', trimmedRelativePath);
const distRoot = path.resolve(repoRoot, 'dist');
const publicCandidatePath = path.resolve(publicRoot, trimmedRelativePath);
const distCandidatePath = path.resolve(distRoot, trimmedRelativePath);
if (
candidatePath.startsWith(distRoot) &&
fs.existsSync(candidatePath) &&
fs.statSync(candidatePath).isFile()
publicCandidatePath.startsWith(publicRoot) &&
fs.existsSync(publicCandidatePath) &&
fs.statSync(publicCandidatePath).isFile()
) {
return candidatePath;
return publicCandidatePath;
}
if (
distCandidatePath.startsWith(distRoot) &&
fs.existsSync(distCandidatePath) &&
fs.statSync(distCandidatePath).isFile()
) {
return distCandidatePath;
}
return webBuildPath;