temp: 更新重定向配置
This commit is contained in:
parent
2fff202ed8
commit
cad914eead
@ -8,5 +8,6 @@
|
|||||||
domain: 'kevisual.xiongxiao.me',
|
domain: 'kevisual.xiongxiao.me',
|
||||||
resources: 'https://minio.xiongxiao.me/resources',
|
resources: 'https://minio.xiongxiao.me/resources',
|
||||||
allowedOrigins: ['localhost', 'xiongxiao.me', 'zxj.im', 'silkyai.cn'],
|
allowedOrigins: ['localhost', 'xiongxiao.me', 'zxj.im', 'silkyai.cn'],
|
||||||
|
home: '/ai/chat',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,8 @@
|
|||||||
"@kevisual/use-config": "^1.0.8",
|
"@kevisual/use-config": "^1.0.8",
|
||||||
"archiver": "^7.0.1",
|
"archiver": "^7.0.1",
|
||||||
"ioredis": "^5.5.0",
|
"ioredis": "^5.5.0",
|
||||||
"nanoid": "^5.1.2"
|
"nanoid": "^5.1.2",
|
||||||
|
"sequelize": "^6.37.5"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"picomatch": "^4.0.2"
|
"picomatch": "^4.0.2"
|
||||||
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@ -29,6 +29,9 @@ importers:
|
|||||||
nanoid:
|
nanoid:
|
||||||
specifier: ^5.1.2
|
specifier: ^5.1.2
|
||||||
version: 5.1.2
|
version: 5.1.2
|
||||||
|
sequelize:
|
||||||
|
specifier: ^6.37.5
|
||||||
|
version: 6.37.5(pg@8.13.3)
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@rollup/plugin-commonjs':
|
'@rollup/plugin-commonjs':
|
||||||
specifier: ^28.0.2
|
specifier: ^28.0.2
|
||||||
|
@ -25,5 +25,5 @@ export default {
|
|||||||
declaration: false,
|
declaration: false,
|
||||||
}), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件
|
}), // 使用 @rollup/plugin-typescript 处理 TypeScript 文件
|
||||||
],
|
],
|
||||||
external: ['ioredis', '@kevisual/router', '@kevisual/use-config'],
|
external: ['ioredis', '@kevisual/router', '@kevisual/use-config', 'sequelize'],
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { App } from '@kevisual/router';
|
import { App } from '@kevisual/router';
|
||||||
|
// import { redis } from './module/redis/redis.ts';
|
||||||
export const app = new App({
|
export const app = new App({
|
||||||
serverOptions: {
|
serverOptions: {
|
||||||
path: '/api/proxy',
|
path: '/api/proxy',
|
||||||
|
@ -27,6 +27,11 @@ type ConfigType = {
|
|||||||
* 允许跨域访问的地址
|
* 允许跨域访问的地址
|
||||||
*/
|
*/
|
||||||
allowOrigin: string[];
|
allowOrigin: string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* home 不在代理范围内跳转到的地址
|
||||||
|
*/
|
||||||
|
home: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,12 +10,13 @@ import { createRefreshHtml } from './html/create-refresh-html.ts';
|
|||||||
const api = config?.api || { host: 'kevisual.xiongxiao.me', path: '/api/router' };
|
const api = config?.api || { host: 'kevisual.xiongxiao.me', path: '/api/router' };
|
||||||
const domain = config?.proxy?.domain || 'kevisual.xiongxiao.me';
|
const domain = config?.proxy?.domain || 'kevisual.xiongxiao.me';
|
||||||
const allowedOrigins = config?.proxy?.allowOrigin || [];
|
const allowedOrigins = config?.proxy?.allowOrigin || [];
|
||||||
|
const home = config?.proxy?.home || '/ai/chat';
|
||||||
|
|
||||||
const noProxyUrl = ['/', '/favicon.ico'];
|
const noProxyUrl = ['/', '/favicon.ico'];
|
||||||
export const handleRequest = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
export const handleRequest = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||||
if (req.url === '/favicon.ico') {
|
if (req.url === '/favicon.ico') {
|
||||||
res.writeHead(200, { 'Content-Type': 'image/x-icon' });
|
res.writeHead(200, { 'Content-Type': 'image/x-icon' });
|
||||||
res.write('proxy no favicon.ico\n');
|
res.end('proxy no favicon.ico\n');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (req.url.startsWith('/api/proxy')) {
|
if (req.url.startsWith('/api/proxy')) {
|
||||||
@ -97,13 +98,13 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
const data = await UserApp.getDomainApp(dns.hostName);
|
const data = await UserApp.getDomainApp(dns.hostName);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
||||||
res.write('Invalid domain\n');
|
res.end('Invalid domain\n');
|
||||||
return res.end();
|
return;
|
||||||
}
|
}
|
||||||
if (!data.user || !data.app) {
|
if (!data.user || !data.app) {
|
||||||
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
||||||
res.write('Invalid domain config\n');
|
res.end('Invalid domain config\n');
|
||||||
return res.end();
|
return;
|
||||||
}
|
}
|
||||||
user = data.user;
|
user = data.user;
|
||||||
app = data.app;
|
app = data.app;
|
||||||
@ -113,6 +114,13 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
const pathname = new URL(req.url, `http://${dns.hostName}`).pathname;
|
const pathname = new URL(req.url, `http://${dns.hostName}`).pathname;
|
||||||
const url = pathname;
|
const url = pathname;
|
||||||
if (!domainApp && noProxyUrl.includes(url)) {
|
if (!domainApp && noProxyUrl.includes(url)) {
|
||||||
|
if (url === '/') {
|
||||||
|
// 获取一下登陆用户,如果没有登陆用户,重定向到ai-chat页面
|
||||||
|
// 重定向到
|
||||||
|
res.writeHead(302, { Location: home });
|
||||||
|
return res.end();
|
||||||
|
}
|
||||||
|
// 不是域名代理,且是在不代理的url当中
|
||||||
res.write('No proxy for this URL\n');
|
res.write('No proxy for this URL\n');
|
||||||
return res.end();
|
return res.end();
|
||||||
}
|
}
|
||||||
|
5
src/module/models.ts
Normal file
5
src/module/models.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { User, UserInit, Org, OrgInit } from '@kevisual/code-center-module';
|
||||||
|
|
||||||
|
export { User, Org };
|
||||||
|
UserInit();
|
||||||
|
OrgInit();
|
@ -1,11 +1,12 @@
|
|||||||
import { Redis } from 'ioredis';
|
import { Redis } from 'ioredis';
|
||||||
import { useConfig } from '@kevisual/use-config';
|
import { useConfig } from '@kevisual/use-config';
|
||||||
|
import { useContextKey } from '@kevisual/use-config/context';
|
||||||
|
|
||||||
const config = useConfig<{
|
const config = useConfig<{
|
||||||
redis: ConstructorParameters<typeof Redis>;
|
redis: ConstructorParameters<typeof Redis>;
|
||||||
}>();
|
}>();
|
||||||
// 配置 Redis 连接
|
const init = () => {
|
||||||
export const redis = new Redis({
|
return new Redis({
|
||||||
host: 'localhost', // Redis 服务器的主机名或 IP 地址
|
host: 'localhost', // Redis 服务器的主机名或 IP 地址
|
||||||
port: 6379, // Redis 服务器的端口号
|
port: 6379, // Redis 服务器的端口号
|
||||||
// password: 'your_password', // Redis 的密码 (如果有)
|
// password: 'your_password', // Redis 的密码 (如果有)
|
||||||
@ -18,6 +19,9 @@ export const redis = new Redis({
|
|||||||
maxRetriesPerRequest: null, // 允许请求重试的次数 (如果需要无限次重试)
|
maxRetriesPerRequest: null, // 允许请求重试的次数 (如果需要无限次重试)
|
||||||
...config.redis,
|
...config.redis,
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
// 配置 Redis 连接
|
||||||
|
export const redis = useContextKey('redis', init);
|
||||||
export const subscriber = redis.duplicate(); // 创建一个订阅者连接
|
export const subscriber = redis.duplicate(); // 创建一个订阅者连接
|
||||||
|
|
||||||
async function ensureKeyspaceNotifications() {
|
async function ensureKeyspaceNotifications() {
|
||||||
|
30
src/module/sequelize.ts
Normal file
30
src/module/sequelize.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { useConfig } from '@kevisual/use-config';
|
||||||
|
import { Sequelize } from 'sequelize';
|
||||||
|
import { useContextKey, useContext } from '@kevisual/use-config/context';
|
||||||
|
|
||||||
|
type PostgresConfig = {
|
||||||
|
postgres: {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
database: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
const config = useConfig<PostgresConfig>();
|
||||||
|
|
||||||
|
const postgresConfig = config.postgres;
|
||||||
|
|
||||||
|
if (!postgresConfig) {
|
||||||
|
console.error('postgres config is required');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
// connect to db
|
||||||
|
export const init = () => {
|
||||||
|
return new Sequelize({
|
||||||
|
dialect: 'postgres',
|
||||||
|
...postgresConfig,
|
||||||
|
// logging: false,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
export const sequelize = useContextKey('sequelize', init);
|
@ -4,10 +4,24 @@ import { redis } from '@/module/redis/redis.ts';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { fileStore } from '../../module/config.ts';
|
import { fileStore } from '../../module/config.ts';
|
||||||
|
|
||||||
|
app
|
||||||
|
.route({
|
||||||
|
path: 'app',
|
||||||
|
key: 'auth-admin',
|
||||||
|
})
|
||||||
|
.define(async (ctx) => {
|
||||||
|
const { user } = ctx.query;
|
||||||
|
if (user !== 'admin') {
|
||||||
|
ctx.throw('Not Found');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.addTo(app);
|
||||||
|
|
||||||
app
|
app
|
||||||
.route({
|
.route({
|
||||||
path: 'app',
|
path: 'app',
|
||||||
key: 'list',
|
key: 'list',
|
||||||
|
middleware: ['auth-admin'],
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const keys = await redis.keys('user:app:*');
|
const keys = await redis.keys('user:app:*');
|
||||||
@ -24,6 +38,7 @@ app
|
|||||||
.route({
|
.route({
|
||||||
path: 'app',
|
path: 'app',
|
||||||
key: 'delete',
|
key: 'delete',
|
||||||
|
middleware: ['auth-admin'],
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const { user, app } = ctx.query;
|
const { user, app } = ctx.query;
|
||||||
@ -76,6 +91,7 @@ app
|
|||||||
.route({
|
.route({
|
||||||
path: 'app',
|
path: 'app',
|
||||||
key: 'get',
|
key: 'get',
|
||||||
|
middleware: ['auth-admin'],
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const { user, app } = ctx.query;
|
const { user, app } = ctx.query;
|
||||||
@ -100,6 +116,7 @@ app
|
|||||||
.route({
|
.route({
|
||||||
path: 'app',
|
path: 'app',
|
||||||
key: 'status',
|
key: 'status',
|
||||||
|
middleware: ['auth-admin'],
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const { user, app } = ctx.query;
|
const { user, app } = ctx.query;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user