fix: define globals correctly
This commit is contained in:
parent
a563d4c0b3
commit
acd042b4de
@ -1,4 +1,5 @@
|
|||||||
import { constants, access, readFile } from 'node:fs/promises';
|
import { constants, access, readFile } from 'node:fs/promises';
|
||||||
|
import { env } from 'node:process';
|
||||||
import { type } from 'arktype';
|
import { type } from 'arktype';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import { parseDocument } from 'yaml';
|
import { parseDocument } from 'yaml';
|
||||||
@ -63,9 +64,9 @@ export async function hp_loadConfig() {
|
|||||||
let path = HEADPLANE_DEFAULT_CONFIG_PATH;
|
let path = HEADPLANE_DEFAULT_CONFIG_PATH;
|
||||||
|
|
||||||
const envs = rootEnvs({
|
const envs = rootEnvs({
|
||||||
HEADPLANE_DEBUG_LOG: process.env.HEADPLANE_DEBUG_LOG,
|
HEADPLANE_DEBUG_LOG: env.HEADPLANE_DEBUG_LOG,
|
||||||
HEADPLANE_CONFIG_PATH: process.env.HEADPLANE_CONFIG_PATH,
|
HEADPLANE_CONFIG_PATH: env.HEADPLANE_CONFIG_PATH,
|
||||||
HEADPLANE_LOAD_ENV_OVERRIDES: process.env.HEADPLANE_LOAD_ENV_OVERRIDES,
|
HEADPLANE_LOAD_ENV_OVERRIDES: env.HEADPLANE_LOAD_ENV_OVERRIDES,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (envs instanceof type.errors) {
|
if (envs instanceof type.errors) {
|
||||||
@ -79,7 +80,6 @@ export async function hp_loadConfig() {
|
|||||||
|
|
||||||
// Load our debug based logger before ANYTHING
|
// Load our debug based logger before ANYTHING
|
||||||
hpServer_loadLogger(envs.HEADPLANE_DEBUG_LOG);
|
hpServer_loadLogger(envs.HEADPLANE_DEBUG_LOG);
|
||||||
|
|
||||||
if (envs.HEADPLANE_CONFIG_PATH) {
|
if (envs.HEADPLANE_CONFIG_PATH) {
|
||||||
path = envs.HEADPLANE_CONFIG_PATH;
|
path = envs.HEADPLANE_CONFIG_PATH;
|
||||||
}
|
}
|
||||||
@ -117,20 +117,17 @@ export async function hp_loadConfig() {
|
|||||||
testOidc(config.oidc);
|
testOidc(config.oidc);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-expect-error: If we remove globalThis we get a runtime error
|
|
||||||
globalThis.__cookie_context = {
|
globalThis.__cookie_context = {
|
||||||
cookie_secret: config.server.cookie_secret,
|
cookie_secret: config.server.cookie_secret,
|
||||||
cookie_secure: config.server.cookie_secure,
|
cookie_secure: config.server.cookie_secure,
|
||||||
};
|
};
|
||||||
|
|
||||||
// @ts-expect-error: If we remove globalThis we get a runtime error
|
|
||||||
globalThis.__hs_context = {
|
globalThis.__hs_context = {
|
||||||
url: config.headscale.url,
|
url: config.headscale.url,
|
||||||
config_path: config.headscale.config_path,
|
config_path: config.headscale.config_path,
|
||||||
config_strict: config.headscale.config_strict,
|
config_strict: config.headscale.config_strict,
|
||||||
};
|
};
|
||||||
|
|
||||||
// @ts-expect-error: If we remove globalThis we get a runtime error
|
|
||||||
globalThis.__integration_context = config.integration;
|
globalThis.__integration_context = config.integration;
|
||||||
|
|
||||||
runtimeConfig = config;
|
runtimeConfig = config;
|
||||||
@ -190,7 +187,7 @@ function coalesceEnv(config: HeadplaneConfig) {
|
|||||||
const rootKeys: string[] = rootEnvs.props.map((prop) => prop.key);
|
const rootKeys: string[] = rootEnvs.props.map((prop) => prop.key);
|
||||||
|
|
||||||
// Typescript is still insanely stupid at nullish filtering
|
// Typescript is still insanely stupid at nullish filtering
|
||||||
const vars = Object.entries(process.env).filter(([key, value]) => {
|
const vars = Object.entries(env).filter(([key, value]) => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,20 +9,19 @@ import mime from 'mime/lite';
|
|||||||
import appContext from '~server/context/app';
|
import appContext from '~server/context/app';
|
||||||
import { loadDevtools, stacksafeTry } from '~server/dev/hot-server';
|
import { loadDevtools, stacksafeTry } from '~server/dev/hot-server';
|
||||||
import prodBuild from '~server/prod-handler';
|
import prodBuild from '~server/prod-handler';
|
||||||
|
import { hp_loadConfig } from './context/loader';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
// Prefix is a build-time constant
|
// Prefix is a build-time constant
|
||||||
const __hp_prefix: string;
|
const __hp_prefix: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const devtools = import.meta.env.DEV ? await loadDevtools() : undefined;
|
|
||||||
|
|
||||||
const prodHandler = import.meta.env.PROD ? await prodBuild() : undefined;
|
|
||||||
|
|
||||||
const buildPath = process.env.BUILD_PATH ?? './build';
|
|
||||||
const baseDir = resolve(join(buildPath, 'client'));
|
|
||||||
|
|
||||||
export const listener: RequestListener = async (req, res) => {
|
export const listener: RequestListener = async (req, res) => {
|
||||||
|
await hp_loadConfig();
|
||||||
|
const devtools = import.meta.env.DEV ? await loadDevtools() : undefined;
|
||||||
|
const prodHandler = import.meta.env.PROD ? await prodBuild() : undefined;
|
||||||
|
const baseDir = resolve(join('./build', 'client'));
|
||||||
|
|
||||||
const url = new URL(`http://${req.headers.host}${req.url}`);
|
const url = new URL(`http://${req.headers.host}${req.url}`);
|
||||||
|
|
||||||
// build:strip
|
// build:strip
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user