-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
78 lines (63 loc) · 2.09 KB
/
server.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const express = require('express');
const path = require('path');
const helmet = require('helmet');
// if (process.env.DB_INIT === "CREATE-DROP") {
// try {
// console.warn("WARN: Database init process is set to CREATE-DROP. Syncing models...");
// sequelize.sync({ force: true });
// console.info("INFO: Sync successful");
// } catch (err) {
// console.error("ERROR:", err);
// }
// }
// var pool = new Pool({
// user: 'omkar',
// password:'w0lo5hSeimPBUrCD',
// host: 'free-tier.gcp-us-central1.cockroachlabs.cloud',
// database: 'cluster0-959.defaultdb',
// port: 26257,
// ssl: {
// ca: fs.readFileSync('certs/cc-ca.crt').toString(),
// }
// });
// pool.connect(function (err, client, done) {
// if (err) {
// console.log(err);
// done();
// } else {
// if (err) {
// console.error('could not connect to cockroachdb', err);
// done();
// } else {
// client.query('CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, firstName STRING(100), lastName STRING(100), email STRING(100), password STRING(100));', (err, res) => {
// if (err) {
// throw err
// } else {
// }
// });
// client.query(';', (err, res) => {
// if (err) {
// throw err
// } else {
// }
// });
// }
// }
// })
const app = express();
app.use(express.json({ extended: false }));
app.use(helmet());
app.use('/api/users', require('./routes/api/users'));
app.use('/api/auth', require('./routes/api/auth'));
app.use('/api/profile', require('./routes/api/profile'));
// Serve static assets in production
if (process.env.NODE_ENV === 'production') {
// Set static folder
app.use(express.static('client/build'));
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});
}
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
module.exports = {app};