-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.js
30 lines (20 loc) · 944 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
import pgPromise from 'pg-promise';
import express from 'express';
import FuelConsumption from './fuel-consumption.js';
import FuelConsumptionAPI from './fuel-consumption-api.js';
const pgp = pgPromise();
const connectionOptions = {
connectionString: process.env.DATABASE_URL || 'postgres://fuel:fuel@localhost:5432/fuel_consumption',
ssl: process.env.NODE_ENV === 'production', // Enable SSL in production
};
const db = pgp(connectionOptions);
const fuelConsumption = FuelConsumption(db);
const fuelConsumptionAPI = FuelConsumptionAPI(fuelConsumption)
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.json());
app.get('/api/vehicles', fuelConsumptionAPI.vehicles);
app.get('/api/vehicle', fuelConsumptionAPI.vehicle);
app.post('/api/vehicle', fuelConsumptionAPI.addVehicle);
app.post('/api/refuel', fuelConsumptionAPI.refuel);
app.listen(PORT, () => console.log(`App started on port: ${PORT}`));