Merge pull request #29 from qtchaos/ssl
Add config support for SSL postgres connections.
This commit is contained in:
commit
886df2ffb4
|
@ -12,6 +12,8 @@ export const ormConfigSchema = z.object({
|
||||||
postgres: z.object({
|
postgres: z.object({
|
||||||
// connection URL for postgres database
|
// connection URL for postgres database
|
||||||
connection: z.string(),
|
connection: z.string(),
|
||||||
|
// whether to use SSL for the connection
|
||||||
|
ssl: z.coerce.boolean().default(false),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,9 @@ export const configSchema = z.object({
|
||||||
// Enable debug logging for MikroORM - Outputs queries and entity management logs
|
// Enable debug logging for MikroORM - Outputs queries and entity management logs
|
||||||
// Do NOT use in production, leaks all sensitive data
|
// Do NOT use in production, leaks all sensitive data
|
||||||
debugLogging: z.coerce.boolean().default(false),
|
debugLogging: z.coerce.boolean().default(false),
|
||||||
|
|
||||||
|
// Enable SSL for the postgres connection
|
||||||
|
ssl: z.coerce.boolean().default(false),
|
||||||
}),
|
}),
|
||||||
crypto: z.object({
|
crypto: z.object({
|
||||||
// session secret. used for signing session tokens
|
// session secret. used for signing session tokens
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ormConf } from '@/config/orm';
|
import { ormConf } from '@/config/orm';
|
||||||
import { makeOrmConfig } from '@/modules/mikro/orm';
|
import { makeOrmConfig } from '@/modules/mikro/orm';
|
||||||
|
|
||||||
export default makeOrmConfig(ormConf.postgres.connection);
|
export default makeOrmConfig(ormConf.postgres.connection, ormConf.postgres.ssl);
|
||||||
|
|
|
@ -18,6 +18,7 @@ export async function setupMikroORM() {
|
||||||
conf.postgres.connection,
|
conf.postgres.connection,
|
||||||
conf.postgres.debugLogging,
|
conf.postgres.debugLogging,
|
||||||
(msg) => log.info(msg),
|
(msg) => log.info(msg),
|
||||||
|
conf.postgres.ssl,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (conf.postgres.syncSchema) {
|
if (conf.postgres.syncSchema) {
|
||||||
|
|
|
@ -2,7 +2,10 @@ import { Options } from '@mikro-orm/core';
|
||||||
import { MikroORM, PostgreSqlDriver } from '@mikro-orm/postgresql';
|
import { MikroORM, PostgreSqlDriver } from '@mikro-orm/postgresql';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
export function makeOrmConfig(url: string): Options<PostgreSqlDriver> {
|
export function makeOrmConfig(
|
||||||
|
url: string,
|
||||||
|
ssl: boolean,
|
||||||
|
): Options<PostgreSqlDriver> {
|
||||||
return {
|
return {
|
||||||
type: 'postgresql',
|
type: 'postgresql',
|
||||||
clientUrl: url,
|
clientUrl: url,
|
||||||
|
@ -13,6 +16,11 @@ export function makeOrmConfig(url: string): Options<PostgreSqlDriver> {
|
||||||
pathTs: './migrations',
|
pathTs: './migrations',
|
||||||
path: './migrations',
|
path: './migrations',
|
||||||
},
|
},
|
||||||
|
driverOptions: {
|
||||||
|
connection: {
|
||||||
|
ssl,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,9 +28,10 @@ export async function createORM(
|
||||||
url: string,
|
url: string,
|
||||||
debug: boolean,
|
debug: boolean,
|
||||||
log: (msg: string) => void,
|
log: (msg: string) => void,
|
||||||
|
ssl: boolean,
|
||||||
) {
|
) {
|
||||||
return await MikroORM.init<PostgreSqlDriver>({
|
return await MikroORM.init<PostgreSqlDriver>({
|
||||||
...makeOrmConfig(url),
|
...makeOrmConfig(url, ssl),
|
||||||
logger: log,
|
logger: log,
|
||||||
debug,
|
debug,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue