-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
44 lines (33 loc) · 1007 Bytes
/
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
import express, { json, Router } from 'express';
import cors from 'cors';
import 'express-async-errors';
import { connectDB } from './config/dbConnection';
import rateLimit from 'express-rate-limit';
import { beerRouter } from './routes/beerRouter';
import { handleError } from './middleware/errorMiddleware';
import { userRouter } from './routes/userRouter';
import 'dotenv/config';
connectDB();
const app = express();
app.use(
cors({
origin: 'http://localhost:3000',
// origin: 'https://beercatalog.networkmanager.pl'
})
);
app.use(json());
app.use(express.urlencoded({ extended: false }));
app.use(
rateLimit({
windowMs: 5 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes)
})
);
const router = Router();
router.use('/beers', beerRouter);
router.use('/users', userRouter);
app.use('/api', router);
app.use(handleError);
app.listen(process.env.PORT, () =>
console.log(`Server started http://localhost:${process.env.PORT}`)
);