-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
46 lines (37 loc) · 1.2 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
import express from 'express';
import pkg from 'pg';
import dotenv from 'dotenv';
import cors from 'cors';
import workoutRouter from './routes/workoutRouter.js';
import exerciseRouter from './routes/exerciseRouter.js';
import workoutExerciseRouter from './routes/workoutExerciseRouter.js';
dotenv.config();
// const pgConnect = `postgres://mharlow9:3l5kE8Jb0vSPPeWFYANqyQM1oJEZldeq@dpg-cnef407109ks738v8h30-a/harlowdb`
// const pgConnectLocal = `postgres://postgres:postgres@localhost:6432/postgres`
const { Pool } = pkg;
let PORT = process.env.PORT || 10000;
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false, // Only use this in development
}
});
const app = express();
// Middleware
app.use(
express.json(),
express.static('dist'),
cors({
origin: '*',
methods: ['GET', 'POST', 'PATCH', 'DELETE'],
allowedHeaders: ['Authorization', 'Content-Type']
})
);
app.set('pool', pool);
// Middleware
app.use('/api/workouts', workoutRouter);
app.use('/api/exercises', exerciseRouter);
app.use('/api/workout-details', workoutExerciseRouter);
app.listen(PORT, () => {
console.log("Listening on port: ", PORT);
});