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{connectDB as i}from"./utils/mongoDB/connectDB.mjs";import{bitbucketRoute as a,bitbucketRouter as o}from"./routes/bitbucket.routes.mjs";import{dictionaryRoute as s,dictionaryRouter as c}from"./routes/dictionary.routes.mjs";import{githubRoute as l,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{connectRedis as y}from"./utils/redis/connectRedis.mjs";import{translateRoute as b,translationRouter as x}from"./routes/translate.routes.mjs";import{userRoute as S,userRouter as C}from"./routes/user.routes.mjs";import{getAuth as w}from"./utils/auth/getAuth.mjs";import{getOAuth2AccessToken as T}from"./controllers/oAuth2.controller.mjs";import{attachOAuthInstance as E,oAuth2Middleware as D}from"./middlewares/oAuth2.middleware.mjs";import{authMiddleware as O}from"./middlewares/sessionAuth.middleware.mjs";import{eventListenerRoute as k,eventListenerRouter as A}from"./routes/eventListener.routes.mjs";import{searchRoute as j,searchRouter as M}from"./routes/search.routes.mjs";import{stripeRoute as N,stripeRouter as P}from"./routes/stripe.routes.mjs";import{tagRoute as F,tagRouter as I}from"./routes/tags.routes.mjs";import{startTranslationWorker as L}from"./services/translationWorker.service.mjs";import{corsOptions as R}from"./utils/cors.mjs";import{stripeWebhook as z}from"./webhooks/stripe.webhook.mjs";import{intlayer as B,t as V}from"fastify-intlayer";import H from"@fastify/rate-limit";import U from"@fastify/compress";import W from"@fastify/cookie";import G from"@fastify/cors";import K from"@fastify/formbody";import q from"@fastify/helmet";import J from"dotenv";import Y from"fastify";(async()=>{let X=Y({disableRequestLogging:!0,trustProxy:!0,routerOptions:{ignoreTrailingSlash:!0}}),Z=`production`;e.info(`run as ${Z}`),J.config({path:[`.env.${Z}.local`,`.env.${Z}`,`.env.local`,`.env`],quiet:!0}),await X.register(q,{contentSecurityPolicy:!1,global:!0}),await X.register(G,R),await X.register(U),await X.register(W),await X.register(K),await X.register(B),await X.register(H,t);let Q=await i();await y(),L(),await X.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 z({...e.raw,body:n,headers:e.headers},t)})}),X.get(`/`,async(e,t)=>t.send(V({en:`Ok - locale: en`,fr:`Ok - locale: fr`,es:`Ok - locale: es`})));let $=w(Q);X.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`})}}}),X.addHook(`onRequest`,O($)),X.addHook(`onRequest`,E),X.post(`/oauth2/token`,T),X.addHook(`preHandler`,D),Z===`development`&&X.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 X.register(C,{prefix:S}),await X.register(g,{prefix:h}),await X.register(v,{prefix:_}),await X.register(I,{prefix:F}),await X.register(c,{prefix:s}),await X.register(P,{prefix:N}),await X.register(r,{prefix:n}),await X.register(A,{prefix:k}),await X.register(M,{prefix:j}),await X.register(m,{prefix:p}),await X.register(u,{prefix:l}),await X.register(f,{prefix:d}),await X.register(o,{prefix:a}),await X.register(x,{prefix:b}),await X.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