Skip to content

Commit

Permalink
feat(server): integrate Sentry for error tracking and performance mon…
Browse files Browse the repository at this point in the history
…itoring
  • Loading branch information
fraineralex committed Dec 9, 2024
1 parent c310b61 commit 8af22e1
Show file tree
Hide file tree
Showing 23 changed files with 2,173 additions and 476 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
node_modules
.env.local
client/dist
dist
*.pem
client_secret_google.json
.dockerignore
Dockerfile
fly.toml
.sentryclirc

53 changes: 30 additions & 23 deletions server/dist/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import express from 'express';
import logger from 'morgan';
import { Server } from 'socket.io';
import { createServer } from 'node:http';
import cors from 'cors';
import dotenv from 'dotenv';
import { userRouter } from './src/router/user.js';
import { createTables } from './src/database/index.js';
import { createClient } from '@libsql/client';
import { SocketRouter } from './src/router/socket.js';
import { ChatRouter } from './src/router/chat.js';
import { checkJwtMiddleware } from './src/middlewares/auth.js';
import { refreshAccessToken } from './src/middlewares/refreshAccessToken.js';
dotenv.config({ path: '.env.local' });

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b81e621d-d0f7-5b88-bdb5-1efa16ebcd3f")}catch(e){}}();
import "./src/utils/instrument.js";
import express from "express";
import logger from "morgan";
import { Server } from "socket.io";
import { createServer } from "node:http";
import cors from "cors";
import dotenv from "dotenv";
import { userRouter } from "./src/router/user.js";
import { createTables } from "./src/database/index.js";
import { createClient } from "@libsql/client";
import { SocketRouter } from "./src/router/socket.js";
import { ChatRouter } from "./src/router/chat.js";
import { checkJwtMiddleware } from "./src/middlewares/auth.js";
import { refreshAccessToken } from "./src/middlewares/refreshAccessToken.js";
import * as Sentry from "@sentry/node";
dotenv.config({ path: ".env.local" });
const port = process.env.PORT ?? 3000;
const clientDomain = process.env.CLIENT_DOMAIN ?? 'http://localhost:5173';
const clientDomain = process.env.CLIENT_DOMAIN ?? "http://localhost:5173";
const client = createClient({
url: process.env.DB_URL ?? '',
authToken: process.env.DB_AUTH_TOKEN ?? '',
url: process.env.DB_URL ?? "",
authToken: process.env.DB_AUTH_TOKEN ?? "",
});
createTables(client);
const app = express();
Expand All @@ -34,11 +38,14 @@ const chatRouter = new ChatRouter(client);
app.use(cors({ origin: clientDomain }));
socketRouter.init();
app.use(express.json());
app.use(logger('dev'));
app.get('/', (req, res) => res.send('Welcome to Chatify API'));
app.get('/api', (req, res) => res.send('Welcome to Chatify API'));
app.use(logger("dev"));
app.get("/", (req, res) => res.send("Welcome to Chatify API"));
app.get("/api", (req, res) => res.send("Welcome to Chatify API"));
app.use(checkJwtMiddleware, refreshAccessToken);
app.use('/api/chats', chatRouter.init());
app.use('/api/users', userRouter);
app.use((req, res) => res.status(404).send('404 Not Found'));
app.use("/api/chats", chatRouter.init());
app.use("/api/users", userRouter);
Sentry.setupExpressErrorHandler(app);
app.use((req, res) => res.status(404).send("404 Not Found"));
server.listen(port, () => console.log(`Server is running in port ${port}`));
//# sourceMappingURL=index.js.map
//# debugId=b81e621d-d0f7-5b88-bdb5-1efa16ebcd3f
4 changes: 4 additions & 0 deletions server/dist/src/constants/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="38a65454-d19d-57e4-a5bd-682b6d94ac11")}catch(e){}}();
export const SOCKET_EVENTS = {
CONNECTION: 'connection',
DISCONNECT: 'disconnect',
Expand All @@ -20,3 +22,5 @@ export const MESSAGES_TYPES = {
STICKER: 'sticker',
UNKNOWN: 'unknown'
};
//# sourceMappingURL=index.js.map
//# debugId=38a65454-d19d-57e4-a5bd-682b6d94ac11
4 changes: 4 additions & 0 deletions server/dist/src/controllers/chat.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6d309ad5-a4fd-544b-bb37-02f479f95f0b")}catch(e){}}();
import { getUserById, getUsersByIds } from '../utils/user.js';
import { MESSAGES_TYPES } from '../constants/index.js';
import { getObjectSignedUrl } from '../utils/s3.js';
Expand Down Expand Up @@ -355,3 +357,5 @@ export class ChatController {
}
}
}
//# sourceMappingURL=chat.js.map
//# debugId=6d309ad5-a4fd-544b-bb37-02f479f95f0b
4 changes: 4 additions & 0 deletions server/dist/src/controllers/socket.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c104dbc3-3af2-5e65-8538-4027e5debc4c")}catch(e){}}();
import { MESSAGES_TYPES, SOCKET_EVENTS } from '../constants/index.js';
import { deleteObject, getObjectSignedUrl, uploadFile } from '../utils/s3.js';
import { generateRandomFileName, optimizeImage } from '../utils/chat.js';
Expand Down Expand Up @@ -198,3 +200,5 @@ export class SocketController {
}
}
}
//# sourceMappingURL=socket.js.map
//# debugId=c104dbc3-3af2-5e65-8538-4027e5debc4c
4 changes: 4 additions & 0 deletions server/dist/src/controllers/user.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1abbf5ab-8ecd-5190-a50c-fb812bc0b14e")}catch(e){}}();
import axios from 'axios';
import dotenv from 'dotenv';
dotenv.config({ path: '.env.local' });
Expand Down Expand Up @@ -130,3 +132,5 @@ export class UserController {
}
}
}
//# sourceMappingURL=user.js.map
//# debugId=1abbf5ab-8ecd-5190-a50c-fb812bc0b14e
4 changes: 4 additions & 0 deletions server/dist/src/database/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="35aadedd-1c9e-536c-8bfd-de7aa9d9f1a2")}catch(e){}}();
export async function createTables(client) {
try {
await client.execute(`
Expand Down Expand Up @@ -38,3 +40,5 @@ export async function createTables(client) {
return;
}
}
//# sourceMappingURL=index.js.map
//# debugId=35aadedd-1c9e-536c-8bfd-de7aa9d9f1a2
4 changes: 4 additions & 0 deletions server/dist/src/middlewares/auth.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="7f15490a-6941-5966-a8cb-a6870930bd88")}catch(e){}}();
import { auth } from 'express-oauth2-jwt-bearer';
import jwt from 'jsonwebtoken';
const publicSigningKey = process.env.AUTH0_PUBLIC_SIGNING_KEY ?? '';
Expand All @@ -23,3 +25,5 @@ export const authSocketMiddleware = (socket, next) => {
}
next();
};
//# sourceMappingURL=auth.js.map
//# debugId=7f15490a-6941-5966-a8cb-a6870930bd88
4 changes: 4 additions & 0 deletions server/dist/src/middlewares/refreshAccessToken.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="4a6edb49-ea3b-5380-967e-e97146d711d7")}catch(e){}}();
import axios from 'axios';
import jwt from 'jsonwebtoken';
const AUTH0_M2M_CLIENT_ID = process.env.AUTH0_M2M_CLIENT_ID ?? '';
Expand Down Expand Up @@ -46,3 +48,5 @@ export async function refreshAccessToken(req, res, next) {
req.accessToken = token;
next();
}
//# sourceMappingURL=refreshAccessToken.js.map
//# debugId=4a6edb49-ea3b-5380-967e-e97146d711d7
4 changes: 4 additions & 0 deletions server/dist/src/router/chat.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a7266524-5186-5c71-9cb7-4c8a546e748a")}catch(e){}}();
import { Router } from 'express';
import { ChatController } from '../controllers/chat.js';
export class ChatRouter {
Expand All @@ -14,3 +16,5 @@ export class ChatRouter {
return router;
}
}
//# sourceMappingURL=chat.js.map
//# debugId=a7266524-5186-5c71-9cb7-4c8a546e748a
4 changes: 4 additions & 0 deletions server/dist/src/router/socket.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="252c067a-7ab7-5a92-9af3-6a1dc29f8a32")}catch(e){}}();
import { SOCKET_EVENTS } from '../constants/index.js';
import { SocketController } from '../controllers/socket.js';
import { authSocketMiddleware } from '../middlewares/auth.js';
Expand All @@ -22,3 +24,5 @@ export class SocketRouter {
});
}
}
//# sourceMappingURL=socket.js.map
//# debugId=252c067a-7ab7-5a92-9af3-6a1dc29f8a32
4 changes: 4 additions & 0 deletions server/dist/src/router/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e47dd8f8-9001-5778-935f-26c423d1c364")}catch(e){}}();
import { Router } from 'express';
import { UserController } from '../controllers/user.js';
export const userRouter = Router();
userRouter.get('/', UserController.getAll);
userRouter.get('/metadata', UserController.getUserMetadata);
userRouter.patch('/metadata', UserController.updateMetadata);
//# sourceMappingURL=user.js.map
//# debugId=e47dd8f8-9001-5778-935f-26c423d1c364
4 changes: 4 additions & 0 deletions server/dist/src/types/chat.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="62622897-5a65-57e6-aca4-f51f534bae6c")}catch(e){}}();
export {};
//# sourceMappingURL=chat.js.map
//# debugId=62622897-5a65-57e6-aca4-f51f534bae6c
4 changes: 4 additions & 0 deletions server/dist/src/types/socket.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c29ae288-55da-5678-813f-087d8331c37e")}catch(e){}}();
export {};
//# sourceMappingURL=socket.js.map
//# debugId=c29ae288-55da-5678-813f-087d8331c37e
4 changes: 4 additions & 0 deletions server/dist/src/types/user.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f323123a-586e-5376-8e83-93d61217b5a6")}catch(e){}}();
export {};
//# sourceMappingURL=user.js.map
//# debugId=f323123a-586e-5376-8e83-93d61217b5a6
4 changes: 4 additions & 0 deletions server/dist/src/utils/chat.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d9f4b3c1-08bf-554e-9e59-254b4e8014c3")}catch(e){}}();
import sharp from 'sharp';
import crypto from 'crypto';
export async function optimizeImage(file) {
Expand Down Expand Up @@ -25,3 +27,5 @@ export function generateRandomFileName(file, bytes = 32) {
: file.filename.split('.').pop() ?? '';
return `${crypto.randomBytes(bytes).toString('hex')}.${fileExtension}`;
}
//# sourceMappingURL=chat.js.map
//# debugId=d9f4b3c1-08bf-554e-9e59-254b4e8014c3
4 changes: 4 additions & 0 deletions server/dist/src/utils/s3.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="2cfd2db4-c7e5-5ab4-ab7c-3ab5b4f55c18")}catch(e){}}();
import { S3Client, PutObjectCommand, DeleteObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/cloudfront-signer';
const s3BucketName = process.env.S3_BUCKET_NAME ?? '';
Expand Down Expand Up @@ -90,3 +92,5 @@ export async function deleteObject(key) {
console.error(error);
}
}
//# sourceMappingURL=s3.js.map
//# debugId=2cfd2db4-c7e5-5ab4-ab7c-3ab5b4f55c18
4 changes: 4 additions & 0 deletions server/dist/src/utils/user.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="bdc7acc6-d9c5-58cd-81be-736dd8920ce8")}catch(e){}}();
import axios from 'axios';
const AUTH0_AUDIENCE = process.env.AUTH0_API_IDENTIFIER ?? '';
export async function getUserById(id, accessToken) {
Expand Down Expand Up @@ -26,3 +28,5 @@ export async function getUsersByIds(ids, accesToken) {
const response = await axios.request(config);
return response.data;
}
//# sourceMappingURL=user.js.map
//# debugId=bdc7acc6-d9c5-58cd-81be-736dd8920ce8
73 changes: 38 additions & 35 deletions server/index.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,56 @@
import express from 'express'
import logger from 'morgan'
import { Server } from 'socket.io'
import { createServer } from 'node:http'
import cors from 'cors'
import dotenv from 'dotenv'
import { userRouter } from './src/router/user.js'
import { createTables } from './src/database/index.js'
import { createClient } from '@libsql/client'
import { SocketRouter } from './src/router/socket.js'
import { ChatRouter } from './src/router/chat.js'
import { checkJwtMiddleware } from './src/middlewares/auth.js'
import { refreshAccessToken } from './src/middlewares/refreshAccessToken.js'

dotenv.config({ path: '.env.local' })
const port = process.env.PORT ?? 3000
const clientDomain = process.env.CLIENT_DOMAIN ?? 'http://localhost:5173'
import './src/utils/instrument.js';
import express from 'express';
import logger from 'morgan';
import { Server } from 'socket.io';
import { createServer } from 'node:http';
import cors from 'cors';
import dotenv from 'dotenv';
import { userRouter } from './src/router/user.js';
import { createTables } from './src/database/index.js';
import { createClient } from '@libsql/client';
import { SocketRouter } from './src/router/socket.js';
import { ChatRouter } from './src/router/chat.js';
import { checkJwtMiddleware } from './src/middlewares/auth.js';
import { refreshAccessToken } from './src/middlewares/refreshAccessToken.js';
import * as Sentry from '@sentry/node';

dotenv.config({ path: '.env.local' });
const port = process.env.PORT ?? 3000;
const clientDomain = process.env.CLIENT_DOMAIN ?? 'http://localhost:5173';

const client = createClient({
url: process.env.DB_URL ?? '',
authToken: process.env.DB_AUTH_TOKEN ?? '',
})
createTables(client)
});
createTables(client);

const app = express()
const server = createServer(app)
const app = express();
const server = createServer(app);
const io = new Server(server, {
cors: { origin: clientDomain },
maxHttpBufferSize: 2e8,
connectionStateRecovery: {
maxDisconnectionDuration: 2 * 60 * 1000,
skipMiddlewares: true,
},
})
});

const socketRouter = new SocketRouter(io, client)
const chatRouter = new ChatRouter(client)
const socketRouter = new SocketRouter(io, client);
const chatRouter = new ChatRouter(client);

app.use(cors({ origin: clientDomain }))
socketRouter.init()
app.use(express.json())
app.use(logger('dev'))
app.use(cors({ origin: clientDomain }));
socketRouter.init();
app.use(express.json());
app.use(logger('dev'));

app.get('/', (req, res) => res.send('Welcome to Chatify API'))
app.get('/api', (req, res) => res.send('Welcome to Chatify API'))
app.get('/', (req, res) => res.send('Welcome to Chatify API'));
app.get('/api', (req, res) => res.send('Welcome to Chatify API'));

app.use(checkJwtMiddleware, refreshAccessToken)
app.use('/api/chats', chatRouter.init())
app.use('/api/users', userRouter)
app.use(checkJwtMiddleware, refreshAccessToken);
app.use('/api/chats', chatRouter.init());
app.use('/api/users', userRouter);

app.use((req, res) => res.status(404).send('404 Not Found'))
Sentry.setupExpressErrorHandler(app);
app.use((req, res) => res.status(404).send('404 Not Found'));

server.listen(port, () => console.log(`Server is running in port ${port}`))
server.listen(port, () => console.log(`Server is running in port ${port}`));
Loading

0 comments on commit 8af22e1

Please sign in to comment.