pull port from env var

This commit is contained in:
Milo Schwartz 2024-10-26 17:13:30 -04:00
parent 50d374d9f6
commit be144fe15d
No known key found for this signature in database
2 changed files with 11 additions and 17 deletions

View file

@ -32,7 +32,7 @@ const environmentSchema = z.object({
prefer_wildcard_cert: z.boolean().optional(), prefer_wildcard_cert: z.boolean().optional(),
}), }),
gerbil: z.object({ gerbil: z.object({
start_port: z.number().positive().gt(0), start_port: portSchema,
base_endpoint: z.string(), base_endpoint: z.string(),
subnet_group: z.string(), subnet_group: z.string(),
block_size: z.number().positive().gt(0), block_size: z.number().positive().gt(0),
@ -120,16 +120,9 @@ if (!parsedConfig.success) {
throw new Error(`Invalid configuration file: ${errors}`); throw new Error(`Invalid configuration file: ${errors}`);
} }
process.env.NEXT_PUBLIC_EXTERNAL_API_BASE_URL = new URL( process.env.SERVER_EXTERNAL_PORT = parsedConfig.data.server.external_port.toString();
"/api/v1", process.env.FLAGS_EMAIL_VERIFICATION_REQUIRED = parsedConfig.data.flags
parsedConfig.data.app.base_url ?.require_email_verification
).href;
process.env.NEXT_PUBLIC_INTERNAL_API_BASE_URL = new URL(
"/api/v1",
`http://${parsedConfig.data.server.internal_hostname}:${parsedConfig.data.server.external_port}`
).href;
process.env.PUBLIC_FLAGS_EMAIL_VERIFICATION_REQUIRED = parsedConfig.data
.flags?.require_email_verification
? "true" ? "true"
: "false"; : "false";

View file

@ -1,20 +1,21 @@
import axios from "axios"; import axios from "axios";
// let origin; let origin;
// if (typeof window !== "undefined") { if (typeof window !== "undefined") {
// origin = window.location.origin; origin = window.location.origin;
// } }
export const api = axios.create({ export const api = axios.create({
baseURL: `http://localhost:3000/api/v1`, baseURL: `${origin}/api/v1`,
timeout: 10000, timeout: 10000,
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}); });
// we can pull from env var here becuase it is only used in the server
export const internal = axios.create({ export const internal = axios.create({
baseURL: `http://localhost:3000/api/v1`, baseURL: `http://localhost:${process.env.SERVER_EXTERNAL_PORT}/api/v1`,
timeout: 10000, timeout: 10000,
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",