feat(auth): added in the intital setup auth
This commit is contained in:
@@ -1,30 +1,29 @@
|
||||
import { toNodeHandler } from "better-auth/node";
|
||||
import express from "express";
|
||||
import morgan from "morgan";
|
||||
import { createLogger } from "./src/logger/logger.controller.js";
|
||||
import { connectProdSql } from "./src/prodSql/prodSqlConnection.controller.js";
|
||||
import { setupRoutes } from "./src/routeHandler.routes.js";
|
||||
import { auth } from "./src/utils/auth.utils.js";
|
||||
import { lstCors } from "./src/utils/cors.utils.js";
|
||||
|
||||
const port = Number(process.env.PORT);
|
||||
|
||||
const startApp = async () => {
|
||||
const createApp = async () => {
|
||||
const log = createLogger({ module: "system", subModule: "main start" });
|
||||
const app = express();
|
||||
let baseUrl = "/";
|
||||
|
||||
// global env that run only in dev
|
||||
if (process.env.NODE_ENV?.trim() !== "production") {
|
||||
app.use(morgan("tiny"));
|
||||
baseUrl = "/lst";
|
||||
}
|
||||
|
||||
// start the connection to the prod sql server
|
||||
connectProdSql();
|
||||
|
||||
app.set("trust proxy", true);
|
||||
app.all(`${baseUrl}api/auth/*splat`, toNodeHandler(auth));
|
||||
app.use(express.json());
|
||||
app.use(lstCors());
|
||||
setupRoutes(baseUrl, app);
|
||||
|
||||
app.listen(port, () => {
|
||||
log.info(`Listening on port ${port}`);
|
||||
});
|
||||
log.info("Express app created");
|
||||
return { app, baseUrl };
|
||||
};
|
||||
|
||||
startApp();
|
||||
export default createApp;
|
||||
|
||||
Reference in New Issue
Block a user