-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.mjs
66 lines (56 loc) · 1.5 KB
/
app.mjs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
import path from "path";
import { dirname, redisUri } from "./variables.mjs";
import AutoLoad from "@fastify/autoload";
import cors from "@fastify/cors";
import PG from "@fastify/postgres";
import Redis from "@fastify/redis";
import Swagger from "@fastify/swagger";
import SwaggerUi from "@fastify/swagger-ui";
import {
sqlPort,
sqlHost,
sqlUser,
sqlPass,
sqlDatabase,
} from "./variables.mjs";
// Pass --options via CLI arguments in command to enable these options.
export var options = {};
export default async (fastify, opts) => {
// Place here your custom code!
// Add Swagger for docs
fastify.register(Swagger, {});
fastify.register(SwaggerUi, {
routePrefix: "/docs",
theme: {
title: "HydraDX API Docs",
},
});
// Do not touch the following lines
// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
fastify.register(AutoLoad, {
dir: path.join(dirname(), "app/plugins"),
options: Object.assign({}, opts),
});
// This loads all plugins defined in routes
// define your routes in one of these
fastify.register(AutoLoad, {
dir: path.join(dirname(), "app/routes"),
options: Object.assign({}, opts),
});
fastify.register(PG, {
host: sqlHost(),
port: sqlPort(),
user: sqlUser(),
password: sqlPass(),
database: sqlDatabase(),
max: 500,
});
fastify.register(Redis, {
url: redisUri(),
});
fastify.register(cors, {
allowedHeaders: "*",
});
};