Skip to content

Commit 9c125a0

Browse files
committed
fly fixes
1 parent 5c9f018 commit 9c125a0

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.DS_Store
3-
.env
3+
.env
4+
fly.toml

index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ import pg from 'pg';
33

44
const PORT = process.env.PORT || 3000;
55

6+
let pool;
7+
68
const fastify = Fastify({
79
logger: true
810
});
911

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);
1215
});
1316

1417
async function initDb () {
1518
const {Pool} = pg;
16-
const pool = new Pool();
19+
pool = new Pool();
1720

1821
pool.on('connect', function () {
1922
console.log('PG CONNECTED');
@@ -34,16 +37,12 @@ async function initDb () {
3437
});
3538

3639
await pool.connect();
37-
38-
// Test query
39-
const result = await pool.query('select version();');
40-
console.log(result.rows[0]);
4140
}
4241

4342
async function start () {
4443
try {
4544
await initDb();
46-
await fastify.listen(PORT);
45+
await fastify.listen(PORT, '0.0.0.0');
4746
} catch (error) {
4847
fastify.log.error(error);
4948
process.exit(1);

0 commit comments

Comments
 (0)