fix: update for init
This commit is contained in:
parent
46cb3d4e75
commit
ae459eabfe
@ -3,7 +3,6 @@ PROXY_PORT=3005
|
||||
PROXY_DOMAIN=localhost
|
||||
PROXY_RESOURCES=http://localhost:9000/resources
|
||||
PROXY_ALLOWED_ORIGINS=localhost,xiongxiao.me,zxj.im
|
||||
PROXY_HOME=/ai/chat
|
||||
|
||||
# 后台代理
|
||||
API_HOST=http://localhost:4005
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "page-proxy",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.6",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
@ -18,7 +18,7 @@
|
||||
],
|
||||
"scripts": {
|
||||
"watch": "rollup -c --watch",
|
||||
"dev": "cross-env NODE_ENV=development nodemon --ignore upload --exec tsx src/index.ts",
|
||||
"dev": "cross-env NODE_ENV=development nodemon --ignore proxy-upload --exec tsx src/index.ts",
|
||||
"dev:watch": "cross-env NODE_ENV=development concurrently -n \"Watch,Dev\" -c \"green,blue\" \"npm run watch\" \"sleep 1 && npm run dev\" ",
|
||||
"build": "rimraf dist && rollup -c",
|
||||
"start": "pm2 start dist/app.mjs --name page-proxy",
|
||||
|
@ -45,6 +45,11 @@ type ConfigType = {
|
||||
*/
|
||||
websiteId: string;
|
||||
};
|
||||
redis?: {
|
||||
host: string;
|
||||
port: number;
|
||||
password?: string;
|
||||
};
|
||||
};
|
||||
|
||||
// export const config = useConfig();
|
||||
@ -67,6 +72,11 @@ export const config: ConfigType = {
|
||||
resources: envConfig.PROXY_RESOURCES,
|
||||
allowedOrigin: (envConfig.PROXY_ALLOWED_ORIGINS as string)?.split(',') || [],
|
||||
},
|
||||
redis: {
|
||||
host: envConfig.REDIS_HOST,
|
||||
port: envConfig.REDIS_PORT,
|
||||
password: envConfig.REDIS_PASSWORD,
|
||||
},
|
||||
stat: {
|
||||
websiteId: envConfig.DATA_WEBSITE_ID,
|
||||
},
|
||||
|
@ -10,6 +10,7 @@ import { fetchApp, fetchDomain, fetchTest } from './query/get-router.ts';
|
||||
import { getAppLoadStatus, setAppLoadStatus } from './redis/get-app-status.ts';
|
||||
import { minioResources } from './minio.ts';
|
||||
import { downloadFileFromMinio } from './proxy/http-proxy.ts';
|
||||
import { logger } from './logger.ts';
|
||||
|
||||
const pipelineAsync = promisify(pipeline);
|
||||
|
||||
@ -194,6 +195,7 @@ export class UserApp {
|
||||
}
|
||||
|
||||
const loadStatus = await getAppLoadStatus(user, app);
|
||||
logger.debug('loadStatus', loadStatus);
|
||||
if (loadStatus.status === 'loading') {
|
||||
// 其他情况,error或者running都可以重新加载
|
||||
return {
|
||||
@ -212,7 +214,7 @@ export class UserApp {
|
||||
return { code: 500, message: 'app status is not running' };
|
||||
}
|
||||
// console.log('fetchData', JSON.stringify(fetchData.data.files, null, 2));
|
||||
|
||||
// const getFileSize
|
||||
this.setLoaded('loading', 'loading');
|
||||
const loadProxy = async () => {
|
||||
const value = fetchData;
|
||||
@ -272,6 +274,7 @@ export class UserApp {
|
||||
await redis.hset('user:app:set:' + app + ':' + user, data);
|
||||
this.setLoaded('running', 'loaded');
|
||||
};
|
||||
logger.debug('loadFilesFn', fetchData.proxy);
|
||||
try {
|
||||
if (fetchData.proxy === true) {
|
||||
await loadProxy();
|
||||
|
@ -12,8 +12,8 @@ import { UserPermission } from '@kevisual/permission';
|
||||
import { getLoginUser } from '@/middleware/auth.ts';
|
||||
import { rediretHome } from './user-home/index.ts';
|
||||
import { aiProxy } from './proxy/ai-proxy.ts';
|
||||
const api = config?.api || { host: 'kevisual.xiongxiao.me', path: '/api/router' };
|
||||
const domain = config?.proxy?.domain || 'kevisual.xiongxiao.me';
|
||||
import { logger } from './logger.ts';
|
||||
const domain = config?.proxy?.domain;
|
||||
const allowedOrigins = config?.proxy?.allowedOrigin || [];
|
||||
|
||||
const noProxyUrl = ['/', '/favicon.ico'];
|
||||
@ -56,7 +56,6 @@ const checkNotAuthPath = (user, app) => {
|
||||
export const handleRequest = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||
const querySearch = new URL(req.url, `http://${req.headers.host}`).searchParams;
|
||||
const password = querySearch.get('p');
|
||||
const loginUser = await getLoginUser(req);
|
||||
if (req.url === '/favicon.ico') {
|
||||
res.writeHead(200, { 'Content-Type': 'image/x-icon' });
|
||||
res.end('proxy no favicon.ico\n');
|
||||
@ -153,7 +152,7 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
||||
return res.end();
|
||||
}
|
||||
// 验证域名
|
||||
if (dns.hostName !== domain) {
|
||||
if (domain && dns.hostName !== domain) {
|
||||
// redis获取域名对应的用户和应用
|
||||
domainApp = true;
|
||||
const data = await UserApp.getDomainApp(dns.hostName);
|
||||
@ -235,7 +234,7 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
||||
|
||||
const userApp = new UserApp({ user, app });
|
||||
let isExist = await userApp.getExist();
|
||||
|
||||
logger.debug('userApp', userApp, isExist);
|
||||
if (!isExist) {
|
||||
try {
|
||||
const { code, loading, message } = await userApp.setCacheData();
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { config } from '../config.ts';
|
||||
import { logger } from '../logger.ts';
|
||||
|
||||
const api = config?.api || { host: 'https://kevisual.cn', path: '/api/router' };
|
||||
const apiPath = api.path || '/api/router';
|
||||
|
@ -23,8 +23,8 @@ export const getAppLoadStatus = async (user: string, app: string): Promise<AppLo
|
||||
};
|
||||
}
|
||||
};
|
||||
export const setAppLoadStatus = async (user: string, app: string, status: AppLoadStatus) => {
|
||||
export const setAppLoadStatus = async (user: string, app: string, status: AppLoadStatus, exp = 3 * 60) => {
|
||||
const key = 'user:app:status:' + app + ':' + user;
|
||||
const value = JSON.stringify(status);
|
||||
await redis.set(key, value);
|
||||
await redis.set(key, value, 'EX', exp); // 5分钟过期
|
||||
};
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { Redis } from 'ioredis';
|
||||
import { useContextKey } from '@kevisual/use-config/context';
|
||||
console.log(process.env.REDIS_HOST);
|
||||
|
||||
import { config } from '../config.ts';
|
||||
const redisConfig = {
|
||||
host: 'localhost', // Redis 服务器的主机名或 IP 地址
|
||||
port: 6379, // Redis 服务器的端口号
|
||||
// password: 'your_password', // Redis 的密码 (如果有)
|
||||
host: config?.redis?.host || 'localhost', // Redis 服务器的主机名或 IP 地址
|
||||
port: config?.redis?.port || 6379, // Redis 服务器的端口号
|
||||
password: config?.redis?.password, // Redis 的密码 (如果有)
|
||||
};
|
||||
const init = () => {
|
||||
return new Redis({
|
||||
|
Loading…
x
Reference in New Issue
Block a user