-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
32 lines (24 loc) · 925 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';
const path = require('path');
const dotenv = require('dotenv');
const fastify = require('fastify');
const fastifyCors = require('fastify-cors');
const fastifyPg = require('fastify-postgres');
const AutoLoad = require('fastify-autoload');
const fastifySwagger = require('fastify-swagger');
const swaggerSchema = require('./src/schemas/swagger');
const run = () => {
dotenv.config();
const { NODE_ENV, DB_URL, TEST_DB_URL } = process.env;
const isTestEnv = NODE_ENV === 'test';
const app = fastify({ logger: !isTestEnv });
app.register(fastifyCors, { origin: true });
app.register(fastifySwagger, swaggerSchema);
app.register(fastifyPg, {
connectionString: isTestEnv ? TEST_DB_URL : DB_URL,
});
app.register(AutoLoad, { dir: path.join(__dirname, 'src', 'plugins') });
app.register(AutoLoad, { dir: path.join(__dirname, 'src', 'services') });
return app;
};
module.exports = run;