forked from provectus/internship_devops_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (27 loc) · 912 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
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const db = require('./database');
const ENV = process.env.NODE_ENV;
const PORT = process.env.port || 5000
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use('/api/cities', require('./api/cities'));
app.use('/api/weather', require('./api/weather'));
if (ENV === 'production') {
app.use(express.static(path.join(__dirname), '../client/build'));
app.use((req, res) => {
res.sendFile(path.join(__dirname, '../client/build/index.html'));
});
}
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});
db.query('SELECT NOW()::timestamp', (err, res) => {
if (err.error)
return console.log(err.error);
console.log(`PostgreSQL connected: ${res[0].now}`);
});
module.exports = app;