-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (29 loc) · 918 Bytes
/
app.js
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
"use strict";
require("dotenv").config();
const path = require("path");
const AutoLoad = require("@fastify/autoload");
const { httpPostJson } = require("./utils/http-actions");
const successHandler = require("./utils/success-handler");
module.exports = async function (fastify, opts) {
fastify.decorate("httpPostRequest", httpPostJson);
fastify.decorate("sendSuccessResponse", successHandler);
//register plugins
fastify.register(AutoLoad, {
dir: path.join(__dirname, "plugins"),
options: Object.assign({}, opts),
dirNameRoutePrefix: false,
ignorePattern: /.*.no-load\.js/,
indexPattern: /^no$/i,
});
//register routes
fastify.register(AutoLoad, {
dir: path.join(__dirname, "routes"),
autoHooksPattern: /.*hooks(\.js|\.cjs)$/i,
autoHooks: true,
cascadeHooks: true,
dirNameRoutePrefix: {
user: "user",
},
options: Object.assign({}, opts),
});
};