-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
57 lines (49 loc) · 1.59 KB
/
app.js
File metadata and controls
57 lines (49 loc) · 1.59 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
54
55
56
57
'use strict'
require('dotenv').config();
const path = require('path');
const AutoLoad = require('fastify-autoload');
const SequelizeFastify = require('sequelize-fastify');
const Auth = require('./services/Auth');
const ModelAssociateSetup = require('./models/AssociateSetupSetup');
module.exports = async function (fastify, opts) {
// Place here your custom code!
fastify.register(
SequelizeFastify,
{
instance: 'sequelize',
sequelizeOptions: {
dialect: 'mysql',
host: process.env.DB_HOST,
port: process.env.DB_PORT,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
}
}
).ready(async () => {
try {
await fastify.sequelize.authenticate();
fastify.log.info('Connection has been established successfully.');
// await fastify.sequelize.sync();
} catch (error) {
fastify.log.error('Unable to connect to the database:', error);
}
});
fastify.register(require('fastify-cors'), {});
fastify.decorateRequest('user', null);
fastify.addHook('onRequest', Auth.verifyJwt(fastify));
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'plugins'),
options: Object.assign({}, opts)
});
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'models'),
options: Object.assign({}, opts)
});
fastify.register(ModelAssociateSetup);
fastify.register(AutoLoad, {
dir: path.join(__dirname, 'routes'),
options: Object.assign({}, opts)
});
//fastify.close();
}