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 {z} from 'zod';
|
||||
|
||||
type Env = z.infer<typeof envSchema>;
|
||||
const envSchema = z.object({
|
||||
POSTGRES_DB: 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;
|
||||
|
||||
if (file && fs.existsSync(file)) {
|
||||
@ -57,16 +63,14 @@ function getCredentials() {
|
||||
}
|
||||
}
|
||||
|
||||
const dialect = new PostgresDialect({
|
||||
pool: new Pool({
|
||||
database: env.POSTGRES_DB,
|
||||
host: env.POSTGRES_HOST,
|
||||
port: env.POSTGRES_PORT,
|
||||
...getCredentials(),
|
||||
max: 10,
|
||||
})
|
||||
})
|
||||
|
||||
export const db = new Kysely<Database>({
|
||||
dialect,
|
||||
export const db = env === 'build-time' ? null : new Kysely<Database>({
|
||||
dialect: new PostgresDialect({
|
||||
pool: new Pool({
|
||||
database: env.POSTGRES_DB,
|
||||
host: env.POSTGRES_HOST,
|
||||
port: env.POSTGRES_PORT,
|
||||
...getCredentials(),
|
||||
max: 10,
|
||||
})
|
||||
}),
|
||||
})
|
||||
|
||||
@ -4,6 +4,14 @@ import {db} from "@/data/database";
|
||||
import * as dFns from "date-fns";
|
||||
|
||||
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());
|
||||
|
||||
const projects = await db.selectFrom('project')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user