fix: 解决部署问题
This commit is contained in:
parent
1e9f209803
commit
61bf2cc73b
@ -3,6 +3,8 @@
|
||||
tokenSecret: '<TOKEN_SECRET>',
|
||||
appPath: 'apps',
|
||||
appName: 'codeflow',
|
||||
domain: '*',
|
||||
'mainApp': 'https://kevisual.xiongxiao.me',
|
||||
postgres: {
|
||||
username: 'root',
|
||||
host: 'localhost',
|
||||
@ -10,6 +12,7 @@
|
||||
password: '*****',
|
||||
port: 5432,
|
||||
},
|
||||
redis: {},
|
||||
minio: {
|
||||
endPoint: 'minio.xiongxiao.me',
|
||||
bucketName: 'resources',
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/code-center",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.3",
|
||||
"description": "code center",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
@ -32,7 +32,7 @@
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@kevisual/auth": "1.0.5",
|
||||
"@kevisual/local-app-manager": "0.1.6",
|
||||
"@kevisual/local-app-manager": "0.1.8",
|
||||
"@kevisual/router": "^0.0.6",
|
||||
"@kevisual/use-config": "^1.0.7",
|
||||
"@types/semver": "^7.5.8",
|
||||
|
12
pnpm-lock.yaml
generated
12
pnpm-lock.yaml
generated
@ -17,8 +17,8 @@ importers:
|
||||
specifier: 1.0.5
|
||||
version: 1.0.5
|
||||
'@kevisual/local-app-manager':
|
||||
specifier: 0.1.6
|
||||
version: 0.1.6(@kevisual/router@0.0.6)(@kevisual/types@0.0.6)(@kevisual/use-config@1.0.7)
|
||||
specifier: 0.1.8
|
||||
version: 0.1.8(@kevisual/router@0.0.6)(@kevisual/types@0.0.6)(@kevisual/use-config@1.0.7)(pm2@5.4.3)
|
||||
'@kevisual/router':
|
||||
specifier: ^0.0.6
|
||||
version: 0.0.6
|
||||
@ -339,12 +339,13 @@ packages:
|
||||
'@kevisual/auth@1.0.5':
|
||||
resolution: {integrity: sha512-GwsLj7unKXi7lmMiIIgdig4LwwLiDJnOy15HHZR5gMbyK6s5/uJiMY5RXPB2+onGzTNDqFo/hXjsD2wkerHPVg==}
|
||||
|
||||
'@kevisual/local-app-manager@0.1.6':
|
||||
resolution: {integrity: sha512-ECIM72GS42++xWisE0MVfaby3wGby9Qz+AphpAzYJ286sbSatY7z5cHYKIVeKwIzqU9pyUlgLFDU8UeKCYpsmA==}
|
||||
'@kevisual/local-app-manager@0.1.8':
|
||||
resolution: {integrity: sha512-3dRstV+g1zZox7NvkXPpQHmil0rU89bXM15msmbmWUB450FIh1WaaQ7pWT6cQKhTuPO+duvSSAXtbbL7A1TqvQ==}
|
||||
peerDependencies:
|
||||
'@kevisual/router': ^0.0.6-alpha-2
|
||||
'@kevisual/types': ^0.0.1
|
||||
'@kevisual/use-config': ^1.0.5
|
||||
pm2: ^5.4.3
|
||||
|
||||
'@kevisual/router@0.0.6':
|
||||
resolution: {integrity: sha512-7FQUY87Zy5A4V30OAggRbGpO/Asd7SUpnhHv8mlxnSFFTto25xpXmjHYp12mu/HJTsHM7RTaxVEyD1DeP44D2A==}
|
||||
@ -2509,11 +2510,12 @@ snapshots:
|
||||
|
||||
'@kevisual/auth@1.0.5': {}
|
||||
|
||||
'@kevisual/local-app-manager@0.1.6(@kevisual/router@0.0.6)(@kevisual/types@0.0.6)(@kevisual/use-config@1.0.7)':
|
||||
'@kevisual/local-app-manager@0.1.8(@kevisual/router@0.0.6)(@kevisual/types@0.0.6)(@kevisual/use-config@1.0.7)(pm2@5.4.3)':
|
||||
dependencies:
|
||||
'@kevisual/router': 0.0.6
|
||||
'@kevisual/types': 0.0.6
|
||||
'@kevisual/use-config': 1.0.7
|
||||
pm2: 5.4.3
|
||||
|
||||
'@kevisual/router@0.0.6':
|
||||
dependencies:
|
||||
|
@ -73,6 +73,8 @@ const config = {
|
||||
'socket.io', // socket.io
|
||||
'minio', // minio
|
||||
|
||||
'pm2',
|
||||
|
||||
'pg', // pg
|
||||
'pino', // pino
|
||||
'pino-pretty', // pino-pretty
|
||||
|
11
script/release/generate-token.mjs
Normal file
11
script/release/generate-token.mjs
Normal file
@ -0,0 +1,11 @@
|
||||
import * as nanoid from 'nanoid';
|
||||
|
||||
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
|
||||
//HMAC-256:推荐 32 字节。
|
||||
// HMAC-512:推荐 64 字节。
|
||||
|
||||
// jsonwentoken 默认使用 HMAC-256 算法,生成 32 字节的 token。
|
||||
|
||||
const v = nanoid.customAlphabet(alphabet, 32);
|
||||
console.log('v', v());
|
@ -108,7 +108,9 @@ const getZip = async () => {
|
||||
|
||||
getZip().then(() => {
|
||||
console.log('zip success');
|
||||
console.log(`envision switchOrg system && envision deploy ./release/${zipName} -v 1.0.0 -k code-center -y y -u`);
|
||||
// 固定上传位置在1.0.0版本,不需要更新,因为是zip文件
|
||||
console.log(`envision switch system && envision deploy ./release/${zipName} -v 1.0.0 -k code-center -y y -u`);
|
||||
|
||||
console.log(`download zip: https://kevisual.xiongxiao.me/system/code-center/${zipName}`);
|
||||
console.log(`download zip:\n\ncurl -O https://kevisual.xiongxiao.me/system/code-center/${zipName} && unzip ${zipName}`);
|
||||
|
||||
});
|
||||
|
69
src/app.ts
69
src/app.ts
@ -6,14 +6,11 @@ import { minioClient } from './modules/minio.ts';
|
||||
import { sequelize } from './modules/sequelize.ts';
|
||||
import { useContextKey, useContext } from '@kevisual/use-config/context';
|
||||
useConfig();
|
||||
export const emit = (channel: string, message?: any) => {
|
||||
redisPublisher.publish(channel, JSON.stringify(message));
|
||||
};
|
||||
export { redis, minioClient, sequelize };
|
||||
|
||||
const init = () => {
|
||||
console.log('init app', global.context);
|
||||
return new App<{ import: any; emit: typeof emit; sequelize: typeof sequelize }>({
|
||||
return new App<{ import: any; sequelize: typeof sequelize }>({
|
||||
serverOptions: {
|
||||
cors: {
|
||||
origin: '*',
|
||||
@ -22,72 +19,8 @@ const init = () => {
|
||||
io: true,
|
||||
routerContext: {
|
||||
import: dynamicImport,
|
||||
emit,
|
||||
sequelize,
|
||||
},
|
||||
});
|
||||
};
|
||||
export const app = useContextKey('app', init);
|
||||
// @ts-ignore
|
||||
// app.name = 'main-app';
|
||||
// console.log('app context', global.context);
|
||||
const clients = [];
|
||||
// 订阅频道 pageEdit, container 单个页面预览 container 整个页面预览
|
||||
type ClientData = {
|
||||
cid?: string; // container id
|
||||
pid?: string[]; // page id
|
||||
cids?: string[]; // container id
|
||||
type: 'page' | 'container' | 'flow';
|
||||
};
|
||||
type MessageData = {
|
||||
source: 'container';
|
||||
data: any;
|
||||
operation?: 'edit';
|
||||
};
|
||||
redisSubscriber.subscribe('pageEdit', () => {
|
||||
console.log('Subscribed to Redis data-updates channel');
|
||||
});
|
||||
redisSubscriber.on('message', (channel, message) => {
|
||||
if (channel !== 'pageEdit') return;
|
||||
const m = JSON.parse(message) as MessageData;
|
||||
clients.forEach((client) => {
|
||||
const data = client.data as any;
|
||||
const { cid, cids = [], pid } = data || {};
|
||||
const wrapper = (data: any) => {
|
||||
const res = {
|
||||
type: 'pageEdit',
|
||||
source: 'container',
|
||||
data,
|
||||
pid,
|
||||
};
|
||||
return JSON.stringify(res);
|
||||
};
|
||||
const { source, data: mData } = m; // 拆包
|
||||
if (source === 'container') {
|
||||
if (cid === mData?.id) {
|
||||
client.ws.send(wrapper(mData));
|
||||
} else if (cids.includes(mData?.id)) {
|
||||
client.ws.send(wrapper(mData));
|
||||
}
|
||||
}
|
||||
// 其他操作 暂时 不处理
|
||||
// TODO
|
||||
});
|
||||
});
|
||||
app.io.addListener('subscribe', async ({ data, end, ws }) => {
|
||||
const { type } = data || {};
|
||||
if (type === 'pageEdit') {
|
||||
clients.push({ ws, data: data.data }); // 拆包,里面包含的type信息,去掉
|
||||
end({ code: 200, data: 'subscribe success' });
|
||||
} else if (type === 'unsubscribe') {
|
||||
const index = clients.findIndex((client) => client.ws === ws);
|
||||
clients.splice(index, 1);
|
||||
end({ code: 200, data: 'unsubscribe success' });
|
||||
} else {
|
||||
end({ code: 404, data: 'subscribe fail' });
|
||||
}
|
||||
ws.on('close', () => {
|
||||
const index = clients.findIndex((client) => client.ws === ws);
|
||||
clients.splice(index, 1);
|
||||
});
|
||||
});
|
||||
|
@ -15,3 +15,5 @@ app.listen(config.port, () => {
|
||||
});
|
||||
app.server.on(uploadMiddleware);
|
||||
// }
|
||||
|
||||
console.log(`run ${config.appName} done`);
|
||||
|
@ -257,7 +257,7 @@ export const createDemoUser = async (username = 'demo', pwd = custom()) => {
|
||||
const u = await User.findOne({ where: { username }, logging: false });
|
||||
if (!u) {
|
||||
const user = await User.createUser(username, pwd, 'demo');
|
||||
console.info('new Users name', user.username);
|
||||
console.info('new Users name', user.username, pwd);
|
||||
return {
|
||||
code: 200,
|
||||
data: { user, pwd: pwd },
|
||||
|
@ -103,23 +103,24 @@ app
|
||||
}
|
||||
console.log('path', path);
|
||||
const check = await appPathCheck({ key });
|
||||
let appType: string;
|
||||
if (check) {
|
||||
if (!force) {
|
||||
ctx.throw(400, 'App already exists, please remove it first');
|
||||
} else {
|
||||
const app = manager.getAppShowInfo(key);
|
||||
const appType = app?.type;
|
||||
appType = app?.type;
|
||||
|
||||
await manager.removeApp(key);
|
||||
if (appType === 'system-app') {
|
||||
// 如果是system-app(主进程运行),就重载
|
||||
selfRestart();
|
||||
}
|
||||
}
|
||||
}
|
||||
const installAppData = await installApp({ path, key });
|
||||
await manager.add(installAppData.showAppInfo);
|
||||
ctx.body = installAppData;
|
||||
if (appType === 'system-app') {
|
||||
// 如果是system-app(主进程运行),就重启服务
|
||||
setTimeout(() => selfRestart(), 3000);
|
||||
}
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
|
@ -48,7 +48,7 @@ app
|
||||
const token = await user.createToken(null, loginType);
|
||||
ctx.res.cookie('token', token.token, {
|
||||
maxAge: token.expireTime,
|
||||
domain: { domain },
|
||||
domain,
|
||||
sameSite: 'lax',
|
||||
httpOnly: true,
|
||||
});
|
||||
|
9
src/scripts/sync-user.ts
Normal file
9
src/scripts/sync-user.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { User } from '../models/user.ts';
|
||||
|
||||
// User.sync({ alter: true, logging: true }).then(() => {
|
||||
// console.log('sync user done');
|
||||
// });
|
||||
|
||||
User.findOne({ where: { username: 'admin' } }).then((user) => {
|
||||
console.log('user', user);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user