diff --git a/package.json b/package.json index de5eb79..a6420f5 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "node-fetch": "^3.3.2", "p-queue": "^8.1.0", "pg": "^8.13.3", - "rollup-plugin-esbuild": "^6.2.0", + "rollup-plugin-esbuild": "^6.2.1", "semver": "^7.7.1", "sequelize": "^6.37.5", "socket.io": "^4.8.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c694d50..fcde86c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -67,9 +67,12 @@ importers: pg: specifier: ^8.13.3 version: 8.13.3 + pm2: + specifier: ^5.4.3 + version: 5.4.3 rollup-plugin-esbuild: - specifier: ^6.2.0 - version: 6.2.0(esbuild@0.25.0)(rollup@4.34.8) + specifier: ^6.2.1 + version: 6.2.1(esbuild@0.25.0)(rollup@4.34.8) semver: specifier: ^7.7.1 version: 7.7.1 @@ -146,9 +149,6 @@ importers: nodemon: specifier: ^3.1.9 version: 3.1.9 - pm2: - specifier: ^5.4.3 - version: 5.4.3 rimraf: specifier: latest version: 6.0.1 @@ -1972,8 +1972,8 @@ packages: rollup: ^3.29.4 || ^4 typescript: ^4.5 || ^5.0 - rollup-plugin-esbuild@6.2.0: - resolution: {integrity: sha512-LbkHaCahA6ceyWzAd6md2yajNS+HfZmZ5o58ShkZp0cQeZOnZECG2D2xWFNBq5SF6X6pfMK2udkZ+wRtvpzyVQ==} + rollup-plugin-esbuild@6.2.1: + resolution: {integrity: sha512-jTNOMGoMRhs0JuueJrJqbW8tOwxumaWYq+V5i+PD+8ecSCVkuX27tGW7BXqDgoULQ55rO7IdNxPcnsWtshz3AA==} engines: {node: '>=14.18.0'} peerDependencies: esbuild: '>=0.18.0' @@ -4224,7 +4224,7 @@ snapshots: proxy-agent@6.3.1: dependencies: agent-base: 7.1.1 - debug: 4.3.7(supports-color@5.5.0) + debug: 4.4.0 http-proxy-agent: 7.0.2 https-proxy-agent: 7.0.5 lru-cache: 7.18.3 @@ -4302,7 +4302,7 @@ snapshots: require-in-the-middle@5.2.0: dependencies: - debug: 4.3.7(supports-color@5.5.0) + debug: 4.4.0 module-details-from-path: 1.0.3 resolve: 1.22.8 transitivePeerDependencies: @@ -4347,7 +4347,7 @@ snapshots: optionalDependencies: '@babel/code-frame': 7.26.2 - rollup-plugin-esbuild@6.2.0(esbuild@0.25.0)(rollup@4.34.8): + rollup-plugin-esbuild@6.2.1(esbuild@0.25.0)(rollup@4.34.8): dependencies: debug: 4.4.0 es-module-lexer: 1.6.0 diff --git a/src/modules/domain.ts b/src/modules/domain.ts index 3516ce6..420ea16 100644 --- a/src/modules/domain.ts +++ b/src/modules/domain.ts @@ -8,4 +8,4 @@ const config = useConfig(); /** * 用来放cookie的域名 */ -export const domain = config.domain || 'xiongxiao.me'; +export const domain = config.domain || ''; // 请在这里填写你的域名 diff --git a/src/route.ts b/src/route.ts index 3545423..4219cc8 100644 --- a/src/route.ts +++ b/src/route.ts @@ -34,15 +34,14 @@ app } user.setTokenUser(tokenUser); const orgs = await user.getOrgs(); - if (orgs.includes('admin')) { ctx.body = 'admin'; - ctx.nextQuery = ctx.query; } else { ctx.throw(403, 'forbidden'); } } catch (e) { - console.error('auth-admin error', e); + console.error(`auth-admin error`, e); + console.error('tokenUser', tokenUser?.id, tokenUser?.username, tokenUser?.uid); ctx.throw(500, e.message); } }) diff --git a/src/routes/micro-app/list.ts b/src/routes/micro-app/list.ts index 0a2c73a..6cf7b06 100644 --- a/src/routes/micro-app/list.ts +++ b/src/routes/micro-app/list.ts @@ -11,6 +11,7 @@ app key: 'upload', middleware: ['auth'], description: 'Upload micro app in server', + isDebug: true, }) .define(async (ctx) => { const { files, collection } = ctx.query?.data; diff --git a/src/routes/micro-app/models.ts b/src/routes/micro-app/models.ts index bb21788..e5d912b 100644 --- a/src/routes/micro-app/models.ts +++ b/src/routes/micro-app/models.ts @@ -38,11 +38,11 @@ MicroAppUploadModel.init( comment: 'id', }, title: { - type: DataTypes.STRING, + type: DataTypes.TEXT, defaultValue: '', }, description: { - type: DataTypes.STRING, + type: DataTypes.TEXT, defaultValue: '', }, tags: { @@ -50,11 +50,11 @@ MicroAppUploadModel.init( defaultValue: [], }, type: { - type: DataTypes.STRING, + type: DataTypes.TEXT, defaultValue: '', }, source: { - type: DataTypes.STRING, + type: DataTypes.TEXT, defaultValue: '', }, data: { @@ -66,7 +66,7 @@ MicroAppUploadModel.init( defaultValue: false, }, uname: { - type: DataTypes.STRING, + type: DataTypes.TEXT, defaultValue: '', }, uid: { diff --git a/src/routes/user/me.ts b/src/routes/user/me.ts index 84bc48b..ea95d02 100644 --- a/src/routes/user/me.ts +++ b/src/routes/user/me.ts @@ -2,7 +2,16 @@ import { app } from '@/app.ts'; import { Org } from '@/models/org.ts'; import { User } from '@/models/user.ts'; import { domain } from '@/modules/domain.ts'; +/** + * 当配置了domain后,创建cookie,当get请求地址的时候,会自动带上cookie + * @param token + * @param ctx + * @returns + */ const createCookie = (token: any, ctx: any) => { + if (!domain) { + return; + } ctx.res.cookie('token', token.token, { maxAge: token.expireTime, domain, @@ -10,6 +19,17 @@ const createCookie = (token: any, ctx: any) => { httpOnly: true, }); }; +const clearCookie = (ctx: any) => { + if (!domain) { + return; + } + ctx.res.cookie('token', '', { + maxAge: 0, + domain, + sameSite: 'lax', + httpOnly: true, + }); +}; app .route({ path: 'user', @@ -64,12 +84,7 @@ app key: 'logout', }) .define(async (ctx) => { - ctx.res.cookie('token', '', { - maxAge: 0, - domain: `${domain}`, - sameSite: 'lax', - httpOnly: true, - }); + clearCookie(ctx); }) .addTo(app); app