const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
const require_logger_index = require('./logger/index.cjs');
const require_utils_rateLimiter = require('./utils/rateLimiter.cjs');
const require_routes_ai_routes = require('./routes/ai.routes.cjs');
const require_routes_dictionary_routes = require('./routes/dictionary.routes.cjs');
const require_routes_newsletter_routes = require('./routes/newsletter.routes.cjs');
const require_routes_organization_routes = require('./routes/organization.routes.cjs');
const require_routes_project_routes = require('./routes/project.routes.cjs');
const require_routes_user_routes = require('./routes/user.routes.cjs');
const require_utils_auth_getAuth = require('./utils/auth/getAuth.cjs');
const require_controllers_oAuth2_controller = require('./controllers/oAuth2.controller.cjs');
const require_middlewares_oAuth2_middleware = require('./middlewares/oAuth2.middleware.cjs');
const require_middlewares_request_middleware = require('./middlewares/request.middleware.cjs');
const require_middlewares_sessionAuth_middleware = require('./middlewares/sessionAuth.middleware.cjs');
const require_routes_eventListener_routes = require('./routes/eventListener.routes.cjs');
const require_routes_search_routes = require('./routes/search.routes.cjs');
const require_routes_stripe_routes = require('./routes/stripe.routes.cjs');
const require_routes_tags_routes = require('./routes/tags.routes.cjs');
const require_utils_cors = require('./utils/cors.cjs');
const require_utils_mongoDB_connectDB = require('./utils/mongoDB/connectDB.cjs');
const require_webhooks_stripe_webhook = require('./webhooks/stripe.webhook.cjs');
let express_intlayer = require("express-intlayer");
let express = require("express");
express = require_rolldown_runtime.__toESM(express);
let better_auth_node = require("better-auth/node");
let compression = require("compression");
compression = require_rolldown_runtime.__toESM(compression);
let cookie_parser = require("cookie-parser");
cookie_parser = require_rolldown_runtime.__toESM(cookie_parser);
let cors = require("cors");
cors = require_rolldown_runtime.__toESM(cors);
let dotenv = require("dotenv");
dotenv = require_rolldown_runtime.__toESM(dotenv);
let helmet = require("helmet");
helmet = require_rolldown_runtime.__toESM(helmet);

//#region src/index.ts
const startServer = async () => {
	const app = (0, express.default)();
	app.disable("x-powered-by");
	app.use((0, helmet.default)());
	app.set("trust proxy", 1);
	const env = app.get("env");
	require_logger_index.logger.info(`run as ${env}`);
	dotenv.default.config({ path: [
		`.env.${env}.local`,
		`.env.${env}`,
		".env.local",
		".env"
	] });
	app.use((0, cookie_parser.default)());
	app.use((0, express_intlayer.intlayer)());
	app.use(/(.*)/, require_utils_rateLimiter.ipLimiter);
	const dbClient = await require_utils_mongoDB_connectDB.connectDB();
	app.post("/webhook/stripe", express.default.raw({ type: "application/json" }), require_webhooks_stripe_webhook.stripeWebhook);
	app.use((0, compression.default)());
	app.use(express.default.urlencoded({ extended: true }));
	app.use((0, cors.default)(require_utils_cors.corsOptions));
	app.get("/", (_req, res) => {
		res.send((0, express_intlayer.t)({
			en: "Ok - locale: en",
			fr: "Ok - locale: fr",
			es: "Ok - locale: es"
		}));
	});
	const auth = require_utils_auth_getAuth.getAuth(dbClient);
	app.all("/api/auth/{*rest}", (0, better_auth_node.toNodeHandler)(auth));
	app.use(/(.*)/, require_middlewares_sessionAuth_middleware.authMiddleware(auth));
	app.use(/(.*)/, require_middlewares_oAuth2_middleware.attachOAuthInstance);
	app.post("/oauth2/token", require_controllers_oAuth2_controller.getOAuth2AccessToken);
	app.use(/(.*)/, require_middlewares_oAuth2_middleware.oAuth2Middleware);
	app.use(express.default.json());
	if (env === "development") app.use(require_middlewares_request_middleware.logAPIRequestURL);
	app.use(require_routes_user_routes.userRoute, require_routes_user_routes.userRouter);
	app.use(require_routes_organization_routes.organizationRoute, require_routes_organization_routes.organizationRouter);
	app.use(require_routes_project_routes.projectRoute, require_routes_project_routes.projectRouter);
	app.use(require_routes_tags_routes.tagRoute, require_routes_tags_routes.tagRouter);
	app.use(require_routes_dictionary_routes.dictionaryRoute, require_routes_dictionary_routes.dictionaryRouter);
	app.use(require_routes_stripe_routes.stripeRoute, require_routes_stripe_routes.stripeRouter);
	app.use(require_routes_ai_routes.aiRoute, require_routes_ai_routes.aiRouter);
	app.use(require_routes_eventListener_routes.eventListenerRoute, require_routes_eventListener_routes.eventListenerRouter);
	app.use(require_routes_search_routes.searchRoute, require_routes_search_routes.searchRouter);
	app.use(require_routes_newsletter_routes.newsletterRoute, require_routes_newsletter_routes.newsletterRouter);
	app.listen(process.env.PORT, () => {
		require_logger_index.logger.info(`Listening on port ${process.env.PORT}`);
	});
};
startServer();

//#endregion
//# sourceMappingURL=index.cjs.map