diff --git a/.env-docker b/.env-docker deleted file mode 100644 index 752a2922..00000000 --- a/.env-docker +++ /dev/null @@ -1,7 +0,0 @@ -ENVIRONMENT=prod -LOG_LEVEL=debug -SAVE_LOGS= -PORT=3000 -INTERNAL_PORT=3001 -CONFIG_PATH=/config -API_VERSION=v1 \ No newline at end of file diff --git a/.env-example b/.env.example similarity index 61% rename from .env-example rename to .env.example index b9e4e702..50cb0bd1 100644 --- a/.env-example +++ b/.env.example @@ -1,7 +1,4 @@ ENVIRONMENT=dev LOG_LEVEL=debug SAVE_LOGS=false -PORT=3000 -INTERNAL_PORT=3001 CONFIG_PATH=./config -API_VERSION=v1 diff --git a/Dockerfile b/Dockerfile index 638751a6..65ec7186 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file +CMD ["npm", "start"] diff --git a/package.json b/package.json index 9b2a7404..8717aa1c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/server/db/index.ts b/server/db/index.ts index 206a4d24..2f778ff8 100644 --- a/server/db/index.ts +++ b/server/db/index.ts @@ -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"), ); diff --git a/server/environment.ts b/server/environment.ts index 78de1e76..7001e2f2 100644 --- a/server/environment.ts +++ b/server/environment.ts @@ -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); diff --git a/server/index.ts b/server/index.ts index 5ef2ba3f..f5a7190e 100644 --- a/server/index.ts +++ b/server/index.ts @@ -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 diff --git a/server/logger.ts b/server/logger.ts index 793e902a..c02df1c3 100644 --- a/server/logger.ts +++ b/server/logger.ts @@ -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; diff --git a/server/traefik-config-provider/index.ts b/server/traefik-config-provider/index.ts index 16a00684..42462d76 100644 --- a/server/traefik-config-provider/index.ts +++ b/server/traefik-config-provider/index.ts @@ -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 };