Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This pull request addresses an Azure deployment issue related to the … #3364

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
52 changes: 47 additions & 5 deletions packages/server/src/DataSource.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
import 'reflect-metadata'
import path from 'path'
import * as fs from 'fs'
import { DataSource } from 'typeorm'
import { getUserHome } from './utils'
import { entities } from './database/entities'
import { sqliteMigrations } from './database/migrations/sqlite'
import { mysqlMigrations } from './database/migrations/mysql'
import { mariadbMigrations } from './database/migrations/mariadb'
import { postgresMigrations } from './database/migrations/postgres'

let appDataSource: DataSource
// Type assertion for DataSource
const DataSource: any = {} as any

// Declare types for Node.js built-ins
declare const process: {
env: {
[key: string]: string | undefined
}
}

declare const Buffer: any
declare const console: any

// Declare minimal types for 'path' and 'fs' modules
declare const path: {
join: (...paths: string[]) => string
resolve: (...paths: string[]) => string
}

declare const fs: {
existsSync: (path: string) => boolean
mkdirSync: (path: string) => void
readFileSync: (path: string, encoding: string) => string
}

let appDataSource: any

export const init = async (): Promise<void> => {
let homePath
Expand Down Expand Up @@ -90,14 +112,34 @@ export const init = async (): Promise<void> => {
}
}

export function getDataSource(): DataSource {
export function getDataSource(): any {
if (appDataSource === undefined) {
init()
}
return appDataSource
}

const getDatabaseSSLFromEnv = () => {
if (process.env.DATABASE_SSL) {
try {
// Attempt to parse DATABASE_SSL as JSON
const sslConfig = JSON.parse(process.env.DATABASE_SSL)

// If parsing succeeds, return the parsed object
if (typeof sslConfig === 'object' && sslConfig !== null) {
// If 'ca' is provided as a file path, read the file
if (sslConfig.ca && typeof sslConfig.ca === 'string' && fs.existsSync(sslConfig.ca)) {
sslConfig.ca = fs.readFileSync(sslConfig.ca, 'utf8')
}
return sslConfig
}
} catch (error) {
// If parsing fails, fall back to the existing behavior
console.warn('Failed to parse DATABASE_SSL as JSON. Falling back to default behavior.')
}
}

// Existing behavior as fallback
if (process.env.DATABASE_SSL_KEY_BASE64) {
return {
rejectUnauthorized: false,
Expand Down
21 changes: 11 additions & 10 deletions packages/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"compilerOptions": {
"lib": ["es2021"],
"target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"experimentalDecorators": true /* Enable experimental support for TC39 stage 2 draft decorators. */,
"emitDecoratorMetadata": true /* Emit design-type metadata for decorated declarations in source files. */,
"module": "commonjs" /* Specify what module code is generated. */,
"lib": ["es2021", "dom"],
"target": "es2021",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"outDir": "dist",
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"strict": true /* Enable all strict type-checking options. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"sourceMap": true,
"strictPropertyInitialization": false,
"declaration": true
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "**/*.test.ts"]
Expand Down