-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (33 loc) · 1008 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
const express = require('express');
const graphqlHTTP = require('express-graphql')
const schema = require('./schema/schema')
const cors = require('cors');
const app = express();
const path = require('path');
const pool = require('./db').pool
// allow cross-origin requests
app.use(cors())
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true
}));
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
}
// Getting PG configs from db file
const db = require('./db')
/**
* ===================================
* Listen to requests on port 4000
* ===================================
*/
const PORT = process.env.PORT || 4000;
const server = app.listen(PORT, () => console.log('~~~ Tuning in to the waves of port '+PORT+' ~~~'));
let onClose = function(){
server.close(() => {
console.log('Process terminated')
pool.end( () => console.log('Shut down db connection pool'));
})
};
process.on('SIGTERM', onClose);
process.on('SIGINT', onClose);