Polish web dist verification
This commit is contained in:
@@ -11,22 +11,8 @@
|
|||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0"
|
content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0"
|
||||||
/>
|
/>
|
||||||
<!-- 由 vite 注入 VITE_APP_TITLE 变量,在 .env 文件内配置 -->
|
|
||||||
<title><%= VITE_APP_TITLE %></title>
|
<title><%= VITE_APP_TITLE %></title>
|
||||||
<link rel="icon" href="/favicon.ico" />
|
<link rel="icon" href="favicon.svg" />
|
||||||
<script>
|
|
||||||
// 生产环境下注入百度统计
|
|
||||||
if (window._VBEN_ADMIN_PRO_APP_CONF_) {
|
|
||||||
var _hmt = _hmt || [];
|
|
||||||
(function () {
|
|
||||||
var hm = document.createElement('script');
|
|
||||||
hm.src =
|
|
||||||
'https://hm.baidu.com/hm.js?97352b16ed2df8c3860cf5a1a65fb4dd';
|
|
||||||
var s = document.getElementsByTagName('script')[0];
|
|
||||||
s.parentNode.insertBefore(hm, s);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ const formSchema = computed((): VbenFormSchema[] => {
|
|||||||
{
|
{
|
||||||
component: 'VbenInput',
|
component: 'VbenInput',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
|
autocomplete: 'username',
|
||||||
placeholder: $t('authentication.usernameTip'),
|
placeholder: $t('authentication.usernameTip'),
|
||||||
},
|
},
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
@@ -133,6 +134,7 @@ const formSchema = computed((): VbenFormSchema[] => {
|
|||||||
{
|
{
|
||||||
component: 'VbenInputPassword',
|
component: 'VbenInputPassword',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
|
autocomplete: 'current-password',
|
||||||
placeholder: $t('authentication.passwordTip'),
|
placeholder: $t('authentication.passwordTip'),
|
||||||
},
|
},
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
import { createReadStream } from 'node:fs';
|
||||||
|
import { stat } from 'node:fs/promises';
|
||||||
|
import http from 'node:http';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
const root = fileURLToPath(new URL('../apps/web-ele/dist', import.meta.url));
|
||||||
|
const host = process.env.HOST || '127.0.0.1';
|
||||||
|
const port = Number(process.env.PORT || 5777);
|
||||||
|
const basePath = process.env.BASE_PATH || '/ai-agent-admin';
|
||||||
|
const apiPrefix = `${basePath}/basic-api`;
|
||||||
|
const rootApiPrefix = '/basic-api';
|
||||||
|
const apiTarget =
|
||||||
|
process.env.API_TARGET || 'http://124.220.21.25/zq-ai-admin/basic-api';
|
||||||
|
|
||||||
|
const mime = {
|
||||||
|
'.css': 'text/css; charset=utf-8',
|
||||||
|
'.html': 'text/html; charset=utf-8',
|
||||||
|
'.ico': 'image/x-icon',
|
||||||
|
'.js': 'application/javascript; charset=utf-8',
|
||||||
|
'.json': 'application/json; charset=utf-8',
|
||||||
|
'.mjs': 'application/javascript; charset=utf-8',
|
||||||
|
'.mp3': 'audio/mpeg',
|
||||||
|
'.png': 'image/png',
|
||||||
|
'.svg': 'image/svg+xml',
|
||||||
|
};
|
||||||
|
|
||||||
|
async function exists(filePath) {
|
||||||
|
try {
|
||||||
|
return (await stat(filePath)).isFile();
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function proxy(req, res) {
|
||||||
|
const targetBase = apiTarget.replace(/\/$/, '');
|
||||||
|
const apiPath = req.url.startsWith(apiPrefix)
|
||||||
|
? req.url.replace(apiPrefix, '')
|
||||||
|
: req.url.replace(rootApiPrefix, '');
|
||||||
|
const target = new URL(`${targetBase}${apiPath}`);
|
||||||
|
const headers = { ...req.headers };
|
||||||
|
delete headers.host;
|
||||||
|
|
||||||
|
let upstream;
|
||||||
|
try {
|
||||||
|
upstream = await fetch(target, {
|
||||||
|
body: ['GET', 'HEAD'].includes(req.method) ? undefined : req,
|
||||||
|
duplex: 'half',
|
||||||
|
headers,
|
||||||
|
method: req.method,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
res.writeHead(502, { 'Content-Type': 'text/plain; charset=utf-8' });
|
||||||
|
res.end(`Proxy upstream unavailable: ${target}\n${error.message}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.writeHead(upstream.status, Object.fromEntries(upstream.headers));
|
||||||
|
if (upstream.body) {
|
||||||
|
res.end(Buffer.from(await upstream.arrayBuffer()));
|
||||||
|
} else {
|
||||||
|
res.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function serve(req, res) {
|
||||||
|
const url = new URL(req.url || '/', `http://${host}:${port}`);
|
||||||
|
if (
|
||||||
|
url.pathname.startsWith(apiPrefix) ||
|
||||||
|
url.pathname.startsWith(rootApiPrefix)
|
||||||
|
) {
|
||||||
|
await proxy(req, res);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url.pathname === '/' || url.pathname === '') {
|
||||||
|
res.writeHead(302, { Location: `${basePath}/` });
|
||||||
|
res.end();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!url.pathname.startsWith(basePath)) {
|
||||||
|
res.writeHead(404);
|
||||||
|
res.end('Not Found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let rel = url.pathname.slice(basePath.length) || '/index.html';
|
||||||
|
if (rel === '/') rel = '/index.html';
|
||||||
|
|
||||||
|
let filePath = path.join(root, rel);
|
||||||
|
if (!(await exists(filePath))) {
|
||||||
|
filePath = path.join(root, 'index.html');
|
||||||
|
}
|
||||||
|
|
||||||
|
const ext = path.extname(filePath);
|
||||||
|
res.setHeader('Content-Type', mime[ext] || 'application/octet-stream');
|
||||||
|
createReadStream(filePath).pipe(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
const server = http.createServer((req, res) => {
|
||||||
|
serve(req, res).catch((error) => {
|
||||||
|
res.writeHead(500);
|
||||||
|
res.end(error?.stack || String(error));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(port, host, () => {
|
||||||
|
console.log(`web-ele dist server: http://${host}:${port}${basePath}/`);
|
||||||
|
console.log(`api proxy: ${apiPrefix} -> ${apiTarget}`);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user