temp
This commit is contained in:
parent
b3c2587903
commit
6a4ff85683
@ -1,10 +1,12 @@
|
|||||||
{
|
{
|
||||||
port: 3005,
|
|
||||||
api: {
|
api: {
|
||||||
host: 'localhost:4002', // 后台代理
|
host: 'localhost:4002', // 后台代理
|
||||||
path: '/api/router',
|
path: '/api/router',
|
||||||
},
|
},
|
||||||
allowedOrigins: ['localhost', 'xiongxiao.me', 'zxj.im'],
|
proxy: {
|
||||||
domain: 'kevisual.xiongxiao.me',
|
port: 3005,
|
||||||
resources: 'minio.xiongxiao.me/resources',
|
domain: 'kevisual.xiongxiao.me',
|
||||||
|
resources: 'minio.xiongxiao.me/resources',
|
||||||
|
allowedOrigins: ['localhost', 'xiongxiao.me', 'zxj.im', 'silkyai.cn'],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
10
package.json
10
package.json
@ -7,7 +7,7 @@
|
|||||||
"app": {
|
"app": {
|
||||||
"key": "page-proxy",
|
"key": "page-proxy",
|
||||||
"entry": "dist/app.mjs",
|
"entry": "dist/app.mjs",
|
||||||
"type": "micro-app",
|
"type": "pm2-system-app",
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
]
|
]
|
||||||
@ -18,12 +18,14 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "cross-env NODE_ENV=development nodemon --ignore upload --exec tsx src/index.ts",
|
"dev": "cross-env NODE_ENV=development nodemon --ignore upload --exec tsx src/index.ts",
|
||||||
"build": "rimraf dist && rollup -c",
|
"build": "rimraf dist && rollup -c",
|
||||||
"deploy": "rsync -avz dist/ light:~/apps/var-proxy/backend",
|
"deploy:light": "rsync -avz dist/ light:~/apps/var-proxy/backend",
|
||||||
"reload": "ssh light pm2 restart proxy",
|
"reload": "ssh light pm2 restart proxy",
|
||||||
"pub": "npm run build && npm run deploy && npm run reload",
|
"pub:light": "npm run build && npm run deploy && npm run reload",
|
||||||
"demo": "rsync -avz dist/ on:~/docker/page-proxy/dist",
|
"demo": "rsync -avz dist/ on:~/docker/page-proxy/dist",
|
||||||
"start": "pm2 start dist/app.mjs --name page-proxy",
|
"start": "pm2 start dist/app.mjs --name page-proxy",
|
||||||
"release": "node ./scripts/release/index.mjs"
|
"release": "node ./scripts/release/index.mjs",
|
||||||
|
"deploy": "envision switch root && envision pack -p -u",
|
||||||
|
"pub": "npm run build && npm run deploy"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { handleRequest } from './module/index.ts';
|
import { handleRequest } from './module/index.ts';
|
||||||
import { useConfig } from '@kevisual/use-config';
|
import { config } from './module/config.ts';
|
||||||
import { app } from './app.ts';
|
import { app } from './app.ts';
|
||||||
import './route/route.ts'
|
import './route/route.ts';
|
||||||
const { port } = useConfig<{ port: number }>();
|
const port = config?.proxy?.port || 3005;
|
||||||
|
|
||||||
app
|
app
|
||||||
.route({
|
.route({
|
||||||
|
33
src/module/config.ts
Normal file
33
src/module/config.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { useConfig } from '@kevisual/use-config';
|
||||||
|
import { useFileStore } from '@kevisual/use-config/file-store';
|
||||||
|
export const fileStore = useFileStore('proxy-upload');
|
||||||
|
|
||||||
|
type ConfigType = {
|
||||||
|
api: {
|
||||||
|
/**
|
||||||
|
* API host address
|
||||||
|
*/
|
||||||
|
host: string;
|
||||||
|
path?: string;
|
||||||
|
port?: number;
|
||||||
|
};
|
||||||
|
proxy: {
|
||||||
|
port?: number;
|
||||||
|
/**
|
||||||
|
* self domain kevisual.xiongxiao.me
|
||||||
|
*/
|
||||||
|
domain: string;
|
||||||
|
/**
|
||||||
|
* resources path
|
||||||
|
* https://minio.xiongxiao.me/resources
|
||||||
|
*/
|
||||||
|
resources: string;
|
||||||
|
/**
|
||||||
|
* allow origin xiongxiao.me zxj.im silkyai.cn
|
||||||
|
* 允许跨域访问的地址
|
||||||
|
*/
|
||||||
|
allowOrigin: string[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const config = useConfig<ConfigType>();
|
@ -1,7 +1,6 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { redis, subscriber } from './redis/redis.ts';
|
import { redis, subscriber } from './redis/redis.ts';
|
||||||
import { useFileStore } from '@kevisual/use-config/file-store';
|
import { config, fileStore } from '../module/config.ts';
|
||||||
import { useConfig } from '@kevisual/use-config';
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
@ -10,8 +9,7 @@ import { promisify } from 'util';
|
|||||||
import { fetchApp, fetchDomain, fetchTest } from './query/get-router.ts';
|
import { fetchApp, fetchDomain, fetchTest } from './query/get-router.ts';
|
||||||
const pipelineAsync = promisify(pipeline);
|
const pipelineAsync = promisify(pipeline);
|
||||||
|
|
||||||
const { resources, api } = useConfig<{ resources: string; api: { host: string; path: string } }>();
|
const { resources } = config?.proxy || { resources: 'https://minio.xiongxiao.me/resources' };
|
||||||
const fileStore = useFileStore('upload');
|
|
||||||
const status: { [key: string]: boolean } = {};
|
const status: { [key: string]: boolean } = {};
|
||||||
const demoData = {
|
const demoData = {
|
||||||
user: 'root',
|
user: 'root',
|
||||||
@ -255,10 +253,7 @@ export const downloadUserAppFiles = async (user: string, app: string, data: type
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (data.type === 'oss') {
|
if (data.type === 'oss') {
|
||||||
let serverPath = 'https://' + resources + '/';
|
let serverPath = new URL(resources).href + '/';
|
||||||
if(resources.includes('localhost')) {
|
|
||||||
serverPath = 'http://' + resources + '/';
|
|
||||||
}
|
|
||||||
// server download file
|
// server download file
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const file = files[i];
|
const file = files[i];
|
||||||
|
@ -1,22 +1,17 @@
|
|||||||
import { getDNS, isLocalhost } from '@/utils/dns.ts';
|
import { getDNS, isLocalhost } from '@/utils/dns.ts';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import { UserApp } from './get-user-app.ts';
|
import { UserApp } from './get-user-app.ts';
|
||||||
import { useFileStore } from '@kevisual/use-config/file-store';
|
import { config, fileStore } from '../module/config.ts';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { useConfig } from '@kevisual/use-config';
|
|
||||||
import { getContentType } from './get-content-type.ts';
|
import { getContentType } from './get-content-type.ts';
|
||||||
import { sleep } from '@/utils/sleep.ts';
|
import { sleep } from '@/utils/sleep.ts';
|
||||||
const { api, domain, allowedOrigins } = useConfig<{
|
|
||||||
api: {
|
|
||||||
host: string;
|
|
||||||
port?: number;
|
|
||||||
};
|
|
||||||
domain: string;
|
|
||||||
allowedOrigins: string[];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const fileStore = useFileStore('upload');
|
const api = config?.api || { host: 'kevisual.xiongxiao.me', path: '/api/router' };
|
||||||
|
const domain = config?.proxy?.domain || 'kevisual.xiongxiao.me';
|
||||||
|
const allowedOrigins = config?.proxy?.allowOrigin || [];
|
||||||
|
|
||||||
|
|
||||||
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') {
|
||||||
@ -34,7 +29,7 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
let header: any = {};
|
let header: any = {};
|
||||||
if (req.headers?.['Authorization']) {
|
if (req.headers?.['Authorization']) {
|
||||||
header.authorization = req.headers['Authorization'];
|
header.authorization = req.headers['Authorization'];
|
||||||
} else if(req.headers?.['authorization']) {
|
} else if (req.headers?.['authorization']) {
|
||||||
header.authorization = req.headers['authorization'];
|
header.authorization = req.headers['authorization'];
|
||||||
}
|
}
|
||||||
if (req.headers?.['Content-Type']) {
|
if (req.headers?.['Content-Type']) {
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
import { useConfig } from '@kevisual/use-config';
|
import { config } from '../config.ts';
|
||||||
|
|
||||||
const { resources, api } = useConfig<{
|
|
||||||
resources: string;
|
|
||||||
api: { host: string; path: string };
|
|
||||||
ƒ;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
|
const api = config?.api || { host: 'kevisual.xiongxiao.me', path: '/api/router' };
|
||||||
const apiPath = api.path || '/api/router';
|
const apiPath = api.path || '/api/router';
|
||||||
export const fetchTest = async (id: string) => {
|
export const fetchTest = async (id: string) => {
|
||||||
const fetchUrl = 'http://' + api.host + apiPath;
|
const fetchUrl = 'http://' + api.host + apiPath;
|
||||||
|
@ -2,8 +2,7 @@ import { UserApp } from '@/module/get-user-app.ts';
|
|||||||
import { app } from '../../app.ts';
|
import { app } from '../../app.ts';
|
||||||
import { redis } from '@/module/redis/redis.ts';
|
import { redis } from '@/module/redis/redis.ts';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { useFileStore } from '@kevisual/use-config/file-store';
|
import { fileStore } from '../../module/config.ts';
|
||||||
const fileStore = useFileStore('upload');
|
|
||||||
|
|
||||||
app
|
app
|
||||||
.route({
|
.route({
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import { UserApp, clearAllUserApp } from '../module/get-user-app.ts';
|
import { UserApp, clearAllUserApp } from '../module/get-user-app.ts';
|
||||||
import { redis } from '../module/redis/redis.ts';
|
import { redis } from '../module/redis/redis.ts';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { useFileStore } from '@kevisual/use-config/file-store';
|
import { config, fileStore } from '../module/config.ts';
|
||||||
const filePath = useFileStore('upload');
|
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
const userApp = new UserApp({ user: 'root', app: 'codeflow' });
|
const userApp = new UserApp({ user: 'root', app: 'codeflow' });
|
||||||
@ -33,7 +32,6 @@ const clearData = async () => {
|
|||||||
// clearData();
|
// clearData();
|
||||||
// clearAllUserApp();
|
// clearAllUserApp();
|
||||||
|
|
||||||
|
|
||||||
const expireData = async () => {
|
const expireData = async () => {
|
||||||
await redis.set('user:app:exist:' + 'codeflow:root', 'value', 'EX', 2);
|
await redis.set('user:app:exist:' + 'codeflow:root', 'value', 'EX', 2);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
@ -45,5 +43,5 @@ const keysData = async () => {
|
|||||||
const keys = await redis.keys('user:app:exist:*');
|
const keys = await redis.keys('user:app:exist:*');
|
||||||
console.log('keys', keys);
|
console.log('keys', keys);
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
};
|
||||||
keysData();
|
keysData();
|
Loading…
x
Reference in New Issue
Block a user