mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-14 22:53:45 +02:00
fix env
This commit is contained in:
parent
8a009f7fbc
commit
5f768f1855
9 changed files with 32 additions and 52 deletions
|
@ -1,7 +0,0 @@
|
||||||
ENVIRONMENT=prod
|
|
||||||
LOG_LEVEL=debug
|
|
||||||
SAVE_LOGS=
|
|
||||||
PORT=3000
|
|
||||||
INTERNAL_PORT=3001
|
|
||||||
CONFIG_PATH=/config
|
|
||||||
API_VERSION=v1
|
|
|
@ -1,7 +1,4 @@
|
||||||
ENVIRONMENT=dev
|
ENVIRONMENT=dev
|
||||||
LOG_LEVEL=debug
|
LOG_LEVEL=debug
|
||||||
SAVE_LOGS=false
|
SAVE_LOGS=false
|
||||||
PORT=3000
|
|
||||||
INTERNAL_PORT=3001
|
|
||||||
CONFIG_PATH=./config
|
CONFIG_PATH=./config
|
||||||
API_VERSION=v1
|
|
|
@ -31,8 +31,8 @@ COPY --from=builder /app/.next ./.next
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
|
|
||||||
# Expose the ports the app runs on
|
# Expose the ports the app runs on
|
||||||
EXPOSE ${EXTERNAL_PORT}
|
EXPOSE 3000
|
||||||
EXPOSE ${INTERNAL_PORT}
|
EXPOSE 3001
|
||||||
|
|
||||||
# Start the application
|
# Start the application
|
||||||
CMD ["npm", "start"]
|
CMD ["npm", "start"]
|
|
@ -9,7 +9,7 @@
|
||||||
"db:hydrate": "npx tsx scripts/hydrate.ts",
|
"db:hydrate": "npx tsx scripts/hydrate.ts",
|
||||||
"db:studio": "drizzle-kit studio",
|
"db:studio": "drizzle-kit studio",
|
||||||
"build": "next build && tsc --project tsconfig.server.json && tsc-alias -p tsconfig.server.json",
|
"build": "next build && tsc --project tsconfig.server.json && tsc-alias -p tsconfig.server.json",
|
||||||
"start": "NODE_ENV=production node dist/server/index.js"
|
"start": "ENVIRONMENT=prod node dist/server/index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "1.7.7",
|
"axios": "1.7.7",
|
||||||
|
|
|
@ -4,6 +4,8 @@ import * as schema from "@server/db/schema";
|
||||||
import environment from "@server/environment";
|
import environment from "@server/environment";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
|
console.log("DB PATH IS:", path.join(environment.CONFIG_PATH, "db", "db.sqlite"))
|
||||||
|
|
||||||
const sqlite = new Database(
|
const sqlite = new Database(
|
||||||
path.join(environment.CONFIG_PATH, "db", "db.sqlite"),
|
path.join(environment.CONFIG_PATH, "db", "db.sqlite"),
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,14 +6,6 @@ const environmentSchema = z.object({
|
||||||
ENVIRONMENT: z.enum(["dev", "prod"]),
|
ENVIRONMENT: z.enum(["dev", "prod"]),
|
||||||
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.string().transform((val) => val === "true"),
|
||||||
EXTERNAL_PORT: z
|
|
||||||
.string()
|
|
||||||
.transform((val) => parseInt(val, 10))
|
|
||||||
.pipe(z.number()),
|
|
||||||
INTERNAL_PORT: z
|
|
||||||
.string()
|
|
||||||
.transform((val) => parseInt(val, 10))
|
|
||||||
.pipe(z.number()),
|
|
||||||
CONFIG_PATH: z.string().transform((val) => {
|
CONFIG_PATH: z.string().transform((val) => {
|
||||||
// validate the path and remove any trailing slashes
|
// validate the path and remove any trailing slashes
|
||||||
const resolvedPath = path.resolve(val);
|
const resolvedPath = path.resolve(val);
|
||||||
|
@ -21,18 +13,14 @@ const environmentSchema = z.object({
|
||||||
? resolvedPath.slice(0, -1)
|
? resolvedPath.slice(0, -1)
|
||||||
: resolvedPath;
|
: resolvedPath;
|
||||||
}),
|
}),
|
||||||
API_VERSION: z.string(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const environment = {
|
const environment = {
|
||||||
ENVIRONMENT: (process.env.ENVIRONMENT as string) || "dev",
|
ENVIRONMENT: (process.env.ENVIRONMENT as string) || "dev",
|
||||||
LOG_LEVEL: (process.env.LOG_LEVEL as string) || "debug",
|
LOG_LEVEL: (process.env.LOG_LEVEL as string) || "debug",
|
||||||
SAVE_LOGS: (process.env.SAVE_LOGS as string) || "false",
|
SAVE_LOGS: (process.env.SAVE_LOGS as string) || "false",
|
||||||
EXTERNAL_PORT: (process.env.EXTERNAL_PORT as string) || "3000",
|
|
||||||
INTERNAL_PORT: (process.env.INTERNAL_PORT as string) || "3001",
|
|
||||||
CONFIG_PATH:
|
CONFIG_PATH:
|
||||||
(process.env.CONFIG_PATH as string) || path.join(__dirname, "config"),
|
(process.env.CONFIG_PATH as string) || path.join(__dirname, "config"),
|
||||||
API_VERSION: (process.env.API_VERSION as string) || "v1",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const parsedConfig = environmentSchema.safeParse(environment);
|
const parsedConfig = environmentSchema.safeParse(environment);
|
||||||
|
|
|
@ -11,8 +11,8 @@ import external from "@server/routers/external";
|
||||||
const dev = environment.ENVIRONMENT !== "prod";
|
const dev = environment.ENVIRONMENT !== "prod";
|
||||||
const app = next({ dev });
|
const app = next({ dev });
|
||||||
const handle = app.getRequestHandler();
|
const handle = app.getRequestHandler();
|
||||||
const mainPort = environment.EXTERNAL_PORT;
|
const mainPort = 3000;
|
||||||
const internalPort = environment.INTERNAL_PORT;
|
const internalPort = 3001;
|
||||||
|
|
||||||
app.prepare().then(() => {
|
app.prepare().then(() => {
|
||||||
// Main server
|
// Main server
|
||||||
|
@ -20,7 +20,7 @@ app.prepare().then(() => {
|
||||||
mainServer.use(helmet());
|
mainServer.use(helmet());
|
||||||
mainServer.use(cors());
|
mainServer.use(cors());
|
||||||
|
|
||||||
const prefix = `/api/${environment.API_VERSION}`;
|
const prefix = `/api/v1`;
|
||||||
mainServer.use(prefix, express.json(), external);
|
mainServer.use(prefix, express.json(), external);
|
||||||
|
|
||||||
// We are using NEXT from here on
|
// We are using NEXT from here on
|
||||||
|
|
|
@ -72,13 +72,13 @@ const logger = winston.createLogger({
|
||||||
transports,
|
transports,
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("uncaughtException", (error) => {
|
// process.on("uncaughtException", (error) => {
|
||||||
logger.error("Uncaught Exception:", { error, stack: error.stack });
|
// logger.error("Uncaught Exception:", { error, stack: error.stack });
|
||||||
process.exit(1);
|
// process.exit(1);
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
process.on("unhandledRejection", (reason, _) => {
|
// process.on("unhandledRejection", (reason, _) => {
|
||||||
logger.error("Unhandled Rejection:", { reason });
|
// logger.error("Unhandled Rejection:", { reason });
|
||||||
});
|
// });
|
||||||
|
|
||||||
export default logger;
|
export default logger;
|
||||||
|
|
|
@ -9,7 +9,7 @@ export async function traefikConfigProvider(_: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
const targets = await getAllTargets();
|
const targets = await getAllTargets();
|
||||||
const traefikConfig = buildTraefikConfig(targets);
|
const traefikConfig = buildTraefikConfig(targets);
|
||||||
logger.debug("Built traefik config");
|
// logger.debug("Built traefik config");
|
||||||
res.status(200).send(traefikConfig);
|
res.status(200).send(traefikConfig);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(`Failed to build traefik config: ${e}`);
|
logger.error(`Failed to build traefik config: ${e}`);
|
||||||
|
@ -20,7 +20,7 @@ export async function traefikConfigProvider(_: Request, res: Response) {
|
||||||
export function buildTraefikConfig(
|
export function buildTraefikConfig(
|
||||||
targets: schema.Target[],
|
targets: schema.Target[],
|
||||||
): DynamicTraefikConfig {
|
): DynamicTraefikConfig {
|
||||||
const middlewareName = "gerbil";
|
const middlewareName = "badger";
|
||||||
|
|
||||||
if (!targets.length) {
|
if (!targets.length) {
|
||||||
return {};
|
return {};
|
||||||
|
@ -29,18 +29,18 @@ export function buildTraefikConfig(
|
||||||
const http: DynamicTraefikConfig["http"] = {
|
const http: DynamicTraefikConfig["http"] = {
|
||||||
routers: {},
|
routers: {},
|
||||||
services: {},
|
services: {},
|
||||||
// middlewares: {
|
middlewares: {
|
||||||
// [middlewareName]: {
|
[middlewareName]: {
|
||||||
// plugin: {
|
plugin: {
|
||||||
// [middlewareName]: {
|
[middlewareName]: {
|
||||||
// // These are temporary values
|
// These are temporary values
|
||||||
// APIEndpoint:
|
apiAddress:
|
||||||
// "http://host.docker.internal:3001/api/v1/gerbil",
|
"http://host.docker.internal:3001/api/v1/badger",
|
||||||
// ValidToken: "abc123",
|
validToken: "abc123",
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const target of targets) {
|
for (const target of targets) {
|
||||||
|
@ -49,7 +49,7 @@ export function buildTraefikConfig(
|
||||||
|
|
||||||
http.routers![routerName] = {
|
http.routers![routerName] = {
|
||||||
entryPoints: [target.method],
|
entryPoints: [target.method],
|
||||||
middlewares: [],
|
middlewares: [middlewareName],
|
||||||
service: serviceName,
|
service: serviceName,
|
||||||
rule: `Host(\`${target.resourceId}\`)`, // assuming resourceId is a valid full hostname
|
rule: `Host(\`${target.resourceId}\`)`, // assuming resourceId is a valid full hostname
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue