-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (39 loc) · 991 Bytes
/
index.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ESM
import Fastify from 'fastify';
import env from 'dotenv';
import path from 'path'
import {pool} from './db/index.mjs';
import {logger} from './schemas/constants.js'
import fastifyAutoload from '@fastify/autoload';
import { fileURLToPath } from 'url';
env.config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const fastify = Fastify({
logger: true,
});
(async () => {
const client = await pool.connect();
try {
const { rows } = await client.query('SELECT current_user');
const currentUser = rows[0].current_user;
logger.info({ currentUser })
} catch (error) {
logger.error({ error });
} finally {
client.release()
}
})();
fastify.register(fastifyAutoload, {
dir: path.join(__dirname, 'routes'),
options: {},
})
const start = async () => {
try {
await fastify.listen({ port: 3000, host: '0.0.0.0' });
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
};
start();