import{logger as e}from"./logger/index.mjs";import{ipLimiter as t}from"./utils/rateLimiter.mjs";import{aiRoute as n,aiRouter as r}from"./routes/ai.routes.mjs";import{processAuditJobs as i}from"./services/audit/recursiveAudit.service.mjs";import{auditRoute as a,auditRouter as o}from"./routes/audit.routes.mjs";import{connectDB as s}from"./utils/mongoDB/connectDB.mjs";import{bitbucketRoute as c,bitbucketRouter as l}from"./routes/bitbucket.routes.mjs";import{dictionaryRoute as ee,dictionaryRouter as te}from"./routes/dictionary.routes.mjs";import{githubRoute as ne,githubRouter as u}from"./routes/github.routes.mjs";import{gitlabRoute as d,gitlabRouter as f}from"./routes/gitlab.routes.mjs";import{newsletterRoute as p,newsletterRouter as m}from"./routes/newsletter.routes.mjs";import{organizationRoute as h,organizationRouter as g}from"./routes/organization.routes.mjs";import{projectRoute as _,projectRouter as v}from"./routes/project.routes.mjs";import{showcaseProjectRoute as y,showcaseProjectRouter as b}from"./routes/showcaseProject.routes.mjs";import{connectRedis as x}from"./utils/redis/connectRedis.mjs";import{translateRoute as S,translationRouter as C}from"./routes/translate.routes.mjs";import{userRoute as w,userRouter as T}from"./routes/user.routes.mjs";import{getAuth as E}from"./utils/auth/getAuth.mjs";import{getOAuth2AccessToken as D}from"./controllers/oAuth2.controller.mjs";import{attachOAuthInstance as O,oAuth2Middleware as k}from"./middlewares/oAuth2.middleware.mjs";import{authMiddleware as re}from"./middlewares/sessionAuth.middleware.mjs";import{eventListenerRoute as A,eventListenerRouter as j}from"./routes/eventListener.routes.mjs";import{searchRoute as M,searchRouter as N}from"./routes/search.routes.mjs";import{stripeRoute as P,stripeRouter as F}from"./routes/stripe.routes.mjs";import{tagRoute as I,tagRouter as L}from"./routes/tags.routes.mjs";import{startTranslationWorker as R}from"./services/translationWorker.service.mjs";import{corsOptions as z}from"./utils/cors.mjs";import{stripeWebhook as B}from"./webhooks/stripe.webhook.mjs";import{intlayer as V,t as H}from"fastify-intlayer";import U from"@fastify/rate-limit";import W from"@fastify/compress";import G from"@fastify/cookie";import K from"@fastify/cors";import q from"@fastify/formbody";import J from"@fastify/helmet";import Y from"dotenv";import X from"fastify";(async()=>{let Z=X({disableRequestLogging:!0,trustProxy:!0,routerOptions:{ignoreTrailingSlash:!0}}),Q=`production`;e.info(`run as ${Q}`),Y.config({path:[`.env.${Q}.local`,`.env.${Q}`,`.env.local`,`.env`],quiet:!0}),await Z.register(J,{contentSecurityPolicy:!1,global:!0}),await Z.register(K,z),await Z.register(W),await Z.register(G),await Z.register(q),await Z.register(V),await Z.register(U,t);let ie=await s();await x(),R(),i().catch(t=>e.error(t)),await Z.register(async e=>{e.addContentTypeParser(`application/json`,{parseAs:`buffer`},(e,t,n)=>{n(null,t)}),e.post(`/webhook/stripe`,async(e,t)=>{let n=e.body;await B({...e.raw,body:n,headers:e.headers},t)})}),Z.get(`/`,async(e,t)=>t.send(H({en:`Ok - locale: en`,fr:`Ok - locale: fr`,es:`Ok - locale: es`})));let $=E(ie);Z.route({method:[`GET`,`POST`],url:`/api/auth/*`,async handler(t,n){try{let e=t.protocol,r=t.headers.host,i=new URL(t.url,`${e}://${r}`),a=new Headers;Object.entries(t.headers).forEach(([e,t])=>{t&&a.append(e,String(t))});let o=new Request(i.toString(),{method:t.method,headers:a,...t.body?{body:JSON.stringify(t.body)}:{}}),s=await $.handler(o);n.status(s.status),s.headers.forEach((e,t)=>{n.header(t,e)});let c=s.body?await s.text():null;return n.send(c)}catch(t){return e.error(`Authentication Error:`,t),n.status(500).send({error:`Internal authentication error`,code:`AUTH_FAILURE`})}}}),Z.addHook(`onRequest`,re($)),Z.addHook(`onRequest`,O),Z.post(`/oauth2/token`,D),Z.addHook(`preHandler`,k),Q===`development`&&Z.addHook(`onRequest`,async t=>{let n={params:t.params,query:t.query,body:t.body,locals:t.locals};e.info(`API Request - ${t.method} - ${t.url} - ${JSON.stringify(n,null,2)}`)}),await Z.register(T,{prefix:w}),await Z.register(g,{prefix:h}),await Z.register(v,{prefix:_}),await Z.register(L,{prefix:I}),await Z.register(te,{prefix:ee}),await Z.register(F,{prefix:P}),await Z.register(r,{prefix:n}),await Z.register(j,{prefix:A}),await Z.register(N,{prefix:M}),await Z.register(m,{prefix:p}),await Z.register(u,{prefix:ne}),await Z.register(f,{prefix:d}),await Z.register(l,{prefix:c}),await Z.register(C,{prefix:S}),await Z.register(b,{prefix:y}),await Z.register(o,{prefix:a}),await Z.listen({port:Number(process.env.PORT)||3100,host:`0.0.0.0`}),e.info(`Listening on port ${process.env.PORT||3100}`)})();
//# sourceMappingURL=index.mjs.map