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