import 'reflect-metadata' ; import 'dotenv-safe/config' ; import { __prod__ , COOKIE_NAME } from '@src/config/constants' ; import express , { Request , Response } from 'express' ; import bodyParser from 'body-parser' ; import session from 'express-session' ; import cors from 'cors' ; import { initConnection } from '@src/utils/initConnection' ; import routes from './routes' ; const main = async ( ) => { await initConnection ( ) ; const app = express ( ) ; app . use ( bodyParser . json ( { limit : '5mb' , } ) ) ; app . use ( bodyParser . urlencoded ( { limit : '5mb' , parameterLimit : 100000 , extended : true , } ) ) ; app . set ( 'trust proxy' , 1 ) ; app . use ( cors ( { origin : process . env . CORS_ORIGIN , credentials : true , } ) ) ; app . use ( session ( { name : COOKIE_NAME , cookie : { maxAge : 1000 * 60 * 60 * 24 * 365 * 1 , httpOnly : true , sameSite : 'lax' , secure : __prod__ , } , saveUninitialized : false , secret : process . env . SESSION_SECRET || 'abigsecret' , resave : false , } ) ) ; app . get ( '/' , async ( _req , res ) => { res . status ( 200 ) . send ( { message : 'SaaS backend running' } ) ; } ) ; app . use ( '/v1' , routes ) ; const port = parseInt ( process . env . PORT || '5000' ) ; app . listen ( port , ( ) => { console . log ( `SaaS server started on port ${ port }` ) ; } ) ; } ; main ( ) . then ( async ( ) => { } ) . catch ( ( err ) => { console . error ( err ) ; } ) ;