-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (38 loc) · 1.48 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import express from 'express';
//import path from 'path';
//import { fileURLToPath } from 'url';
import cookieParser from 'cookie-parser';
import logger from 'morgan';
import './mongodb/connection.js';
import rateLimiterMiddleware from './middlewares/rateLimiterMiddleware.js';
import corsMiddleware from './middlewares/corsMiddleware.js';
import authMiddleware from './middlewares/authMiddleware.js';
import { mainRouter } from './routes/index.js';
import { loginRouter } from "./routes/login/index.js";
import { logoutRouter } from "./routes/logout.js";
import { inviteRouter } from './routes/invite/index.js';
import { populateRouter } from './routes/populate.js';
const app = express();
import cors from 'cors';
app.use(cors());
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
//Added for __dirname creation - REQUIRED FOR PUBLIC FOLDER ACTIVATION
/*
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.use(express.static(path.join(__dirname, 'public')));
*/
// apply rate limiter to all requests
app.use(rateLimiterMiddleware);
// apply cross origin request security check to all requests except GET/
app.use(corsMiddleware);
// apply auth session check & refresh to all requests
app.use(authMiddleware);
app.use('/', mainRouter, loginRouter, logoutRouter);
app.use('/invite', inviteRouter);
app.use('/populate', populateRouter);
import './discord/index.js';
export default app;