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