-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugins.js
More file actions
53 lines (52 loc) · 1.36 KB
/
plugins.js
File metadata and controls
53 lines (52 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import fastifyMailer from "fastify-mailer"
import fastifyAutoload from "@fastify/autoload"
import fastifyRedis from "@fastify/redis"
import fastifyMongo from "@fastify/mongodb"
import path from "path"
import { RedisService } from "./src/service/redis-service.js"
import { MongoService } from "./src/service/mongo-service.js"
/**
* @param {import("fastify").FastifyInstance} app
*/
export default (app) => {
app.register(fastifyMailer, {
defaults: { from: `Jaga Otp <${process.env.MAILER_EMAIL}>` },
transport: {
host: process.env.MAILER_HOST,
port: process.env.MAILER_PORT,
auth: {
user: process.env.MAILER_USERNAME,
pass: process.env.MAILER_PASSWORD,
},
},
})
app.register(fastifyAutoload, {
dir: path.join(__dirname, "src/routes"),
options: { prefix: "/api" },
})
app
.register(fastifyMongo, {
url: process.env.MONGO_URL,
database: "jagadb",
})
.after((err) => {
if (err) {
console.log(err)
throw err
}
const mongo = new MongoService(app.mongo)
app.decorate("mongoService", mongo)
})
app
.register(fastifyRedis, {
url: process.env.REDIS_URL,
})
.after((err) => {
if (err) {
console.log(err)
throw err
}
const redis = new RedisService(app.redis)
app.decorate("redisService", redis)
})
}