-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
50 lines (39 loc) · 1.39 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
import express, { Express, Request, Response } from 'express';
import config from '@src/config/config';
import helmet from 'helmet';
import cookieParser from 'cookie-parser';
import cors from 'cors';
import { setCorsCredentials } from '@src/middlewares/cors/credentials';
import { corsOptions } from '@src/config/cors';
import { logger } from '@src/utils/log/logger';
import { connectDB } from '@src/config/database';
import verifyAuthentication from '@src/middlewares/auth/verifyAuthentication';
import authRoutes from '@src/routes/auth.routes';
import productRoutes from '@src/routes/product.routes';
import checkoutRoutes from '@src/routes/checkout.routes';
const app: Express = express();
connectDB();
app.use(helmet());
app.use(setCorsCredentials);
app.use(cors(corsOptions));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(cookieParser());
if (config.ENVIRONMENT === 'production') {
app.use(express.static('./dist-vue'));
}
// routes do not required authentication
// auth routes
app.use('/api/auth', authRoutes);
// checkout
app.use('/api/checkout', checkoutRoutes);
// auth middleware
app.use(verifyAuthentication);
// auth protected routes
app.use('/api/products', productRoutes);
app.listen(config.PORT, () => {
logger.info(`server is running on port ${config.PORT}`);
});
app.get('*', (req: Request, res: Response) => {
res.sendFile('./dist-vue/index.html');
});