File tree 2 files changed +9
-9
lines changed
2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change 1
1
node_modules
2
2
.DS_Store
3
- .env
3
+ .env
4
+ fly.toml
Original file line number Diff line number Diff line change @@ -3,17 +3,20 @@ import pg from 'pg';
3
3
4
4
const PORT = process . env . PORT || 3000 ;
5
5
6
+ let pool ;
7
+
6
8
const fastify = Fastify ( {
7
9
logger : true
8
10
} ) ;
9
11
10
- fastify . get ( '/' , function ( request , reply ) {
11
- reply . send ( 'hello world' ) ;
12
+ fastify . get ( '/' , async function ( request , reply ) {
13
+ const result = await pool . query ( 'select version();' ) ;
14
+ reply . send ( result . rows [ 0 ] . version ) ;
12
15
} ) ;
13
16
14
17
async function initDb ( ) {
15
18
const { Pool} = pg ;
16
- const pool = new Pool ( ) ;
19
+ pool = new Pool ( ) ;
17
20
18
21
pool . on ( 'connect' , function ( ) {
19
22
console . log ( 'PG CONNECTED' ) ;
@@ -34,16 +37,12 @@ async function initDb () {
34
37
} ) ;
35
38
36
39
await pool . connect ( ) ;
37
-
38
- // Test query
39
- const result = await pool . query ( 'select version();' ) ;
40
- console . log ( result . rows [ 0 ] ) ;
41
40
}
42
41
43
42
async function start ( ) {
44
43
try {
45
44
await initDb ( ) ;
46
- await fastify . listen ( PORT ) ;
45
+ await fastify . listen ( PORT , '0.0.0.0' ) ;
47
46
} catch ( error ) {
48
47
fastify . log . error ( error ) ;
49
48
process . exit ( 1 ) ;
You can’t perform that action at this time.
0 commit comments