-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.ts
51 lines (40 loc) · 1.29 KB
/
index.ts
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
import express from 'express';
import sequelize from './config/db.config';
import userRouterHandler from './routes/userRouter';
import rbacRouterHandler from './routes/rbacRouter';
import authRouter from './routes/authRouter';
import swaggerDocument from './swagger_output.json';
import swaggerUi from 'swagger-ui-express';
import cors from 'cors';
import { config } from 'dotenv'; // ES6 import for dotenv
import { errorHandler, routeNotFound } from './middlewares/error';
config(); // Load environment variables from .env file
const app = express();
app.options('*',cors());
app.use(
cors({
origin: '*',
credentials: true,
})
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
sequelize
.sync({ force: false })
.then(() => {
console.log('Database & tables created!');
})
.catch((err: unknown) => {
console.error('Error creating database and tables:', err);
});
app.use('/api/v1/auth', userRouterHandler);
app.use('/api/v1/roles', rbacRouterHandler);
app.use('/api/v1/authorize', authRouter);
app.use('/api/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use(errorHandler);
app.use(routeNotFound);
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server started on port ${PORT}`);
});
export default app;