Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ async function start() {
},
});

await startMcp(app);
try {
await startMcp(app);
} catch (e) {
Logger.error('Failed to initialize Mastra MCP server:', e);
}

app.useGlobalPipes(
new ValidationPipe({
Expand Down
2 changes: 1 addition & 1 deletion libraries/nestjs-libraries/src/chat/mastra.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { PostgresStore } from '@mastra/pg';

export const pStore = new PostgresStore({
id: 'postiz-store',
connectionString: process.env.DATABASE_URL!,
connectionString: process.env.DATABASE_DIRECT_URL || process.env.DATABASE_URL!,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the non-null assertion operator ! on process.env.DATABASE_URL is unsafe because if both DATABASE_DIRECT_URL and DATABASE_URL are missing, it will pass undefined to PostgresStore, leading to a runtime crash with a cryptic error. It is safer to validate that at least one of these environment variables is defined and throw a clear configuration error if they are missing.

  connectionString: (() => {
    const url = process.env.DATABASE_DIRECT_URL || process.env.DATABASE_URL;
    if (!url) {
      throw new Error('Database connection URL is missing. Please set DATABASE_DIRECT_URL or DATABASE_URL.');
    }
    return url;
  })(),

});
Loading