Fix issue attempting to pre-render pages that queried the database
All checks were successful
Build and Publish Docker Container / build (push) Successful in 3m48s
All checks were successful
Build and Publish Docker Container / build (push) Successful in 3m48s
This commit is contained in:
parent
9ba7c34902
commit
3d0c09bba9
@ -4,6 +4,7 @@ import {Kysely, PostgresDialect} from 'kysely'
|
|||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
import {z} from 'zod';
|
import {z} from 'zod';
|
||||||
|
|
||||||
|
type Env = z.infer<typeof envSchema>;
|
||||||
const envSchema = z.object({
|
const envSchema = z.object({
|
||||||
POSTGRES_DB: z.string(),
|
POSTGRES_DB: z.string(),
|
||||||
POSTGRES_HOST: z.string(),
|
POSTGRES_HOST: z.string(),
|
||||||
@ -38,9 +39,14 @@ const envSchema = z.object({
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const env = envSchema.parse(process.env);
|
const buildTime = process.env.NEXT_PHASE === 'phase-production-build';
|
||||||
|
const env = buildTime ? 'build-time' : envSchema.parse(process.env);
|
||||||
|
|
||||||
|
function fileOrEnv(fileKey: keyof Env, valueKey: keyof Env): string | undefined {
|
||||||
|
if (env == 'build-time') {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function fileOrEnv(fileKey: keyof typeof env, valueKey: keyof typeof env): string | undefined {
|
|
||||||
const file: string = env[fileKey] as string;
|
const file: string = env[fileKey] as string;
|
||||||
|
|
||||||
if (file && fs.existsSync(file)) {
|
if (file && fs.existsSync(file)) {
|
||||||
@ -57,16 +63,14 @@ function getCredentials() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dialect = new PostgresDialect({
|
export const db = env === 'build-time' ? null : new Kysely<Database>({
|
||||||
pool: new Pool({
|
dialect: new PostgresDialect({
|
||||||
database: env.POSTGRES_DB,
|
pool: new Pool({
|
||||||
host: env.POSTGRES_HOST,
|
database: env.POSTGRES_DB,
|
||||||
port: env.POSTGRES_PORT,
|
host: env.POSTGRES_HOST,
|
||||||
...getCredentials(),
|
port: env.POSTGRES_PORT,
|
||||||
max: 10,
|
...getCredentials(),
|
||||||
})
|
max: 10,
|
||||||
})
|
})
|
||||||
|
}),
|
||||||
export const db = new Kysely<Database>({
|
|
||||||
dialect,
|
|
||||||
})
|
})
|
||||||
|
|||||||
@ -4,6 +4,14 @@ import {db} from "@/data/database";
|
|||||||
import * as dFns from "date-fns";
|
import * as dFns from "date-fns";
|
||||||
|
|
||||||
export async function getDataSQL(config: OverviewConfig): Promise<Data> {
|
export async function getDataSQL(config: OverviewConfig): Promise<Data> {
|
||||||
|
// If we're in build-time, we don't have access to the database
|
||||||
|
if (!db) {
|
||||||
|
return {
|
||||||
|
projects: [],
|
||||||
|
timeEntries: [],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let projectIds = config.subjects.map((subject) => subject.projectId.toString());
|
let projectIds = config.subjects.map((subject) => subject.projectId.toString());
|
||||||
|
|
||||||
const projects = await db.selectFrom('project')
|
const projects = await db.selectFrom('project')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user