-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (23 loc) · 889 Bytes
/
app.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
const express = require('express');
const dotenv = require('dotenv');
const bodyParser = require('body-parser');
const cors = require('cors');
const { sequelize } = require('./models');
const authRoutes = require('./routes/auth');
const userRoutes = require('./routes/users');
const orgRoutes = require('./routes/organisations');
const errorHandler = require('./middlewares/errorHandler');
dotenv.config(); // Load environment variables from .env file
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(express.json());
// Test the database connection
sequelize.authenticate()
.then(() => console.log('PostgreSQL connected'))
.catch(err => console.error('Unable to connect to the database:', err));
app.use('/auth', authRoutes);
app.use('/api/users', userRoutes);
app.use('/api/organisations', orgRoutes);
app.use(errorHandler);
module.exports = app;