diff --git a/.env-example b/.env-example index 4ef3863f..b9e4e702 100644 --- a/.env-example +++ b/.env-example @@ -1,7 +1,7 @@ ENVIRONMENT=dev LOG_LEVEL=debug -SAVE_LOGS= +SAVE_LOGS=false PORT=3000 INTERNAL_PORT=3001 CONFIG_PATH=./config -API_VERSION=v1 \ No newline at end of file +API_VERSION=v1 diff --git a/server/db/schema.ts b/server/db/schema.ts index 7f326ade..ad71eaea 100644 --- a/server/db/schema.ts +++ b/server/db/schema.ts @@ -67,4 +67,4 @@ export type Site = InferSelectModel; export type Resource = InferSelectModel; export type ExitNode = InferSelectModel; export type Route = InferSelectModel; -export type Target = InferSelectModel; \ No newline at end of file +export type Target = InferSelectModel; diff --git a/server/environment.ts b/server/environment.ts index 744cf3d7..43767afe 100644 --- a/server/environment.ts +++ b/server/environment.ts @@ -18,14 +18,14 @@ const environment = { PORT: (process.env.PORT as string) || "3000", INTERNAL_PORT: (process.env.INTERNAL_PORT as string) || "3001", CONFIG_PATH: process.env.CONFIG_PATH as string, - API_VERSION: process.env.API_VERSION as string, + API_VERSION: (process.env.API_VERSION as string) || "v1", }; const parsedConfig = environmentSchema.safeParse(environment); if (!parsedConfig.success) { - const errors = fromError(parsedConfig.error); - throw new Error(`Invalid environment configuration: ${errors}`); + const errors = fromError(parsedConfig.error); + throw new Error(`Invalid environment configuration: ${errors}`); } export default parsedConfig.data; diff --git a/server/index.ts b/server/index.ts index 23c8516f..0f96f033 100644 --- a/server/index.ts +++ b/server/index.ts @@ -7,33 +7,19 @@ import helmet from "helmet"; import cors from "cors"; import internal from "@server/routers/internal"; import external from "@server/routers/external"; -import Database from 'better-sqlite3'; -import { drizzle } from 'drizzle-orm/better-sqlite3'; const dev = environment.ENVIRONMENT !== "prod"; const app = next({ dev }); const handle = app.getRequestHandler(); const mainPort = environment.PORT; const internalPort = environment.INTERNAL_PORT; -let db: Database.Database; app.prepare().then(() => { - // Open the SQLite database connection - // const sqlite = new Database(`${environment.CONFIG_PATH}/db/db.sqlite`, { verbose: console.log }); - const sqlite = new Database(`${environment.CONFIG_PATH}/db/db.sqlite`); - const db = drizzle(sqlite); - // Main server const mainServer = express(); mainServer.use(helmet()); mainServer.use(cors()); - // Middleware to attach the database to the request - mainServer.use((req, res, next) => { - (req as any).db = db; - next(); - }); - const prefix = `/api/${environment.API_VERSION}`; mainServer.use(prefix, express.json(), external); @@ -53,21 +39,16 @@ app.prepare().then(() => { internalServer.use(helmet()); internalServer.use(cors()); - // Middleware to attach the database to the request - internalServer.use((req, res, next) => { - (req as any).db = db; - next(); - }); - internalServer.use(prefix, express.json(), internal); internalServer.listen(internalPort, (err?: any) => { if (err) throw err; - logger.info(`Internal server is running on http://localhost:${internalPort}`); + logger.info( + `Internal server is running on http://localhost:${internalPort}`, + ); }); }); -process.on('SIGINT', () => { - db.close(); +process.on("SIGINT", () => { process.exit(0); -}); \ No newline at end of file +});