mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-30 14:39:29 +02:00
use bools and numbers in config instead of parsing from string
This commit is contained in:
parent
b07ffad317
commit
37130bd6de
2 changed files with 27 additions and 43 deletions
|
@ -2,19 +2,19 @@ app:
|
||||||
name: Pangolin
|
name: Pangolin
|
||||||
base_url: http://localhost:3000
|
base_url: http://localhost:3000
|
||||||
log_level: warning
|
log_level: warning
|
||||||
save_logs: "false"
|
save_logs: false
|
||||||
|
|
||||||
server:
|
server:
|
||||||
external_port: "3000"
|
external_port: 3000
|
||||||
internal_port: "3001"
|
internal_port: 3001
|
||||||
internal_hostname: pangolin
|
internal_hostname: pangolin
|
||||||
secure_cookies: "true"
|
secure_cookies: true
|
||||||
|
|
||||||
traefik:
|
traefik:
|
||||||
cert_resolver: "letsencrypt"
|
cert_resolver: letsencrypt
|
||||||
http_entrypoint: "web"
|
http_entrypoint: web
|
||||||
https_entrypoint: "websecure"
|
https_entrypoint: websecure
|
||||||
|
|
||||||
rate_limit:
|
rate_limit:
|
||||||
window_minutes: "1"
|
window_minutes: 1
|
||||||
max_requests: "100"
|
max_requests: 100
|
|
@ -11,19 +11,13 @@ const environmentSchema = z.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
base_url: z.string().url(),
|
base_url: z.string().url(),
|
||||||
log_level: z.enum(["debug", "info", "warn", "error"]),
|
log_level: z.enum(["debug", "info", "warn", "error"]),
|
||||||
save_logs: z.string().transform((val) => val === "true"),
|
save_logs: z.boolean(),
|
||||||
}),
|
}),
|
||||||
server: z.object({
|
server: z.object({
|
||||||
external_port: z
|
external_port: z.number().positive().gt(0).lte(65535),
|
||||||
.string()
|
internal_port: z.number().positive().gt(0).lte(65535),
|
||||||
.transform((val) => parseInt(val, 10))
|
|
||||||
.pipe(z.number()),
|
|
||||||
internal_port: z
|
|
||||||
.string()
|
|
||||||
.transform((val) => parseInt(val, 10))
|
|
||||||
.pipe(z.number()),
|
|
||||||
internal_hostname: z.string(),
|
internal_hostname: z.string(),
|
||||||
secure_cookies: z.string().transform((val) => val === "true"),
|
secure_cookies: z.boolean(),
|
||||||
}),
|
}),
|
||||||
traefik: z.object({
|
traefik: z.object({
|
||||||
http_entrypoint: z.string(),
|
http_entrypoint: z.string(),
|
||||||
|
@ -31,28 +25,13 @@ const environmentSchema = z.object({
|
||||||
cert_resolver: z.string().optional(),
|
cert_resolver: z.string().optional(),
|
||||||
}),
|
}),
|
||||||
rate_limit: z.object({
|
rate_limit: z.object({
|
||||||
window_minutes: z
|
window_minutes: z.number().positive().gt(0),
|
||||||
.string()
|
max_requests: z.number().positive().gt(0),
|
||||||
.transform((val) => parseInt(val, 10))
|
|
||||||
.pipe(z.number()),
|
|
||||||
max_requests: z
|
|
||||||
.string()
|
|
||||||
.transform((val) => parseInt(val, 10))
|
|
||||||
.pipe(z.number()),
|
|
||||||
}),
|
}),
|
||||||
email: z
|
email: z
|
||||||
.object({
|
.object({
|
||||||
smtp_host: z.string().optional(),
|
smtp_host: z.string().optional(),
|
||||||
smtp_port: z
|
smtp_port: z.number().optional(),
|
||||||
.string()
|
|
||||||
.optional()
|
|
||||||
.transform((val) => {
|
|
||||||
if (val) {
|
|
||||||
return parseInt(val, 10);
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
})
|
|
||||||
.pipe(z.number().optional()),
|
|
||||||
smtp_user: z.string().optional(),
|
smtp_user: z.string().optional(),
|
||||||
smtp_pass: z.string().optional(),
|
smtp_pass: z.string().optional(),
|
||||||
no_reply: z.string().email().optional(),
|
no_reply: z.string().email().optional(),
|
||||||
|
@ -68,7 +47,7 @@ const loadConfig = (configPath: string) => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Error loading configuration file: ${error.message}`,
|
`Error loading configuration file: ${error.message}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -88,19 +67,24 @@ if (!environment) {
|
||||||
const exampleConfigPath = path.join("config.example.yml");
|
const exampleConfigPath = path.join("config.example.yml");
|
||||||
if (fs.existsSync(exampleConfigPath)) {
|
if (fs.existsSync(exampleConfigPath)) {
|
||||||
try {
|
try {
|
||||||
const exampleConfigContent = fs.readFileSync(exampleConfigPath, "utf8");
|
const exampleConfigContent = fs.readFileSync(
|
||||||
|
exampleConfigPath,
|
||||||
|
"utf8"
|
||||||
|
);
|
||||||
fs.writeFileSync(configFilePath1, exampleConfigContent, "utf8");
|
fs.writeFileSync(configFilePath1, exampleConfigContent, "utf8");
|
||||||
environment = loadConfig(configFilePath1);
|
environment = loadConfig(configFilePath1);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Error creating configuration file from example: ${error.message}`,
|
`Error creating configuration file from example: ${error.message}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error("No configuration file found and no example configuration available");
|
throw new Error(
|
||||||
|
"No configuration file found and no example configuration available"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,11 +101,11 @@ if (!parsedConfig.success) {
|
||||||
|
|
||||||
process.env.NEXT_PUBLIC_EXTERNAL_API_BASE_URL = new URL(
|
process.env.NEXT_PUBLIC_EXTERNAL_API_BASE_URL = new URL(
|
||||||
"/api/v1",
|
"/api/v1",
|
||||||
parsedConfig.data.app.base_url,
|
parsedConfig.data.app.base_url
|
||||||
).href;
|
).href;
|
||||||
process.env.NEXT_PUBLIC_INTERNAL_API_BASE_URL = new URL(
|
process.env.NEXT_PUBLIC_INTERNAL_API_BASE_URL = new URL(
|
||||||
"/api/v1",
|
"/api/v1",
|
||||||
`http://${parsedConfig.data.server.internal_hostname}:${parsedConfig.data.server.external_port}`,
|
`http://${parsedConfig.data.server.internal_hostname}:${parsedConfig.data.server.external_port}`
|
||||||
).href;
|
).href;
|
||||||
process.env.NEXT_PUBLIC_APP_NAME = parsedConfig.data.app.name;
|
process.env.NEXT_PUBLIC_APP_NAME = parsedConfig.data.app.name;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue