Skip to content

Commit

Permalink
修复 shell 变量初始化检查,更新 sentry 版本
Browse files Browse the repository at this point in the history
  • Loading branch information
whyour committed Aug 18, 2024
1 parent a743aa8 commit af5de83
Show file tree
Hide file tree
Showing 14 changed files with 802 additions and 147 deletions.
3 changes: 1 addition & 2 deletions back/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './loaders/sentry'
import 'reflect-metadata'; // We need this in order to use @Decorators
import config from './config';
import express from 'express';
Expand All @@ -10,8 +11,6 @@ async function startServer() {

await require('./loaders/initFile').default();

await require('./loaders/sentry').default({ expressApp: app });

await require('./loaders/app').default({ expressApp: app });

const server = app
Expand Down
2 changes: 1 addition & 1 deletion back/config/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export async function parseVersion(path: string): Promise<IVersion> {
return load(await fs.readFile(path, 'utf8')) as IVersion;
}

export async function parseContentVersion(content: string): Promise<IVersion> {
export function parseContentVersion(content: string): IVersion {
return load(content) as IVersion;
}

Expand Down
4 changes: 2 additions & 2 deletions back/loaders/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export default ({ app }: { app: Application }) => {

app.use(errors());

Sentry.setupExpressErrorHandler(app);

app.use(
(
err: Error & { status: number },
Expand Down Expand Up @@ -178,8 +180,6 @@ export default ({ app }: { app: Application }) => {
res: Response,
next: NextFunction,
) => {
Sentry.captureException(err);

res.status(err.status || 500);
res.json({
code: err.status || 500,
Expand Down
48 changes: 22 additions & 26 deletions back/loaders/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
import { Application } from 'express';
import * as Sentry from '@sentry/node';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import Logger from './logger';
import config from '../config';
import fs from 'fs';
import { parseVersion } from '../config/util';

export default async ({ expressApp }: { expressApp: Application }) => {
const { version } = await parseVersion(config.versionFile);
import config from '../config';
import { parseContentVersion } from '../config/util';

Sentry.init({
ignoreErrors: [
/SequelizeUniqueConstraintError/i,
/Validation error/i,
/UnauthorizedError/i,
/celebrate request validation failed/i,
],
dsn: 'https://[email protected]/6122819',
integrations: [
new Sentry.Integrations.Http({ tracing: true }),
new Sentry.Integrations.Express({ app: expressApp }),
],
tracesSampleRate: 0.8,
release: version,
});
let version = '1.0.0';
try {
const content = fs.readFileSync(config.versionFile, 'utf-8');
({ version } = parseContentVersion(content));
} catch (error) {}

expressApp.use(Sentry.Handlers.requestHandler());
expressApp.use(Sentry.Handlers.tracingHandler());
Sentry.init({
ignoreErrors: [
/SequelizeUniqueConstraintError/i,
/Validation error/i,
/UnauthorizedError/i,
/celebrate request validation failed/i,
],
dsn: 'https://[email protected]/6122819',
integrations: [nodeProfilingIntegration()],
tracesSampleRate: 0.5,
release: version,
});

Logger.info('✌️ Sentry loaded');
console.log('✌️ Sentry loaded');
};
Logger.info('✌️ Sentry loaded');
console.log('✌️ Sentry loaded');
3 changes: 0 additions & 3 deletions back/loaders/sock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default async ({ server }: { server: Server }) => {
if (data) {
const { token = '', tokens = {} } = safeJSONParse(data);
if (headerToken === token || tokens[platform] === headerToken) {
conn.write(JSON.stringify({ type: 'ping', message: 'hanhh' }));
sockService.addClient(conn);

conn.on('data', (message) => {
Expand All @@ -33,8 +32,6 @@ export default async ({ server }: { server: Server }) => {
});

return;
} else {
conn.write(JSON.stringify({ type: 'ping', message: 'whyour' }));
}
}

Expand Down
1 change: 0 additions & 1 deletion back/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ app.get('/api/health', (req, res) => {

app
.listen(config.publicPort, '0.0.0.0', async () => {
await require('./loaders/sentry').default({ expressApp: app });
await require('./loaders/db').default();

Logger.debug(`✌️ 公共服务启动成功!`);
Expand Down
2 changes: 1 addition & 1 deletion back/services/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export default class SystemService {
timeout: 30000,
},
);
lastVersionContent = await parseContentVersion(result.body);
lastVersionContent = parseContentVersion(result.body);
} catch (error) {}

if (!lastVersionContent) {
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"private": true,
"scripts": {
"start": "concurrently -n w: npm:start:*",
"start:front": "max dev",
"start:back": "nodemon",
"start:update": "ts-node -P tsconfig.back.json ./back/update.ts",
"start:public": "ts-node -P tsconfig.back.json ./back/public.ts",
"start:rpc": "ts-node -P tsconfig.back.json ./back/schedule/index.ts",
"start:back": "nodemon",
"start:front": "max dev",
"build:front": "max build",
"build:back": "tsc -p tsconfig.back.json",
"panel": "npm run build:back && node static/build/app.js",
Expand Down Expand Up @@ -59,7 +59,8 @@
"dependencies": {
"@grpc/grpc-js": "^1.8.13",
"@otplib/preset-default": "^12.0.1",
"@sentry/node": "^7.12.1",
"@sentry/node": "^8.26.0",
"@sentry/profiling-node": "8.26.0",
"body-parser": "^1.19.2",
"celebrate": "^15.0.1",
"chokidar": "^3.5.3",
Expand Down Expand Up @@ -107,7 +108,8 @@
"@ant-design/pro-layout": "6.38.22",
"@monaco-editor/react": "4.2.1",
"@react-hook/resize-observer": "^1.2.6",
"@sentry/react": "^7.12.1",
"react-router-dom": "6.26.1",
"@sentry/react": "^8.26.0",
"@types/body-parser": "^1.19.2",
"@types/cors": "^2.8.12",
"@types/cross-spawn": "^6.0.2",
Expand Down
Loading

0 comments on commit af5de83

Please sign in to comment.