-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (41 loc) · 1.52 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
import { resolve } from 'path';
import './src/database';
import express from 'express';
import cors from 'cors'
import userRoutes from './src/routes/userRoutes';
import tokenRoutes from './src/routes/tokenRoutes';
import shopRoutes from './src/routes/shopRoutes';
import productRoutes from './src/routes/productRoutes';
import orderRoutes from './src/routes/orderRoutes';
import addressRoutes from './src/routes/addressRoutes';
import creditCardRoutes from './src/routes/creditCardRoutes'
class App {
constructor() {
// Every time that you create a instance of the "App" class
// you'll call all the constructor functions.
this.app = express();
this.middlewares();
this.routes();
}
// Functions that stay in the middle of certain "actions".
// The "action required" needs to pass through these functions to reach the final objective.
middlewares() {
this.app.use(express.urlencoded({ extended: true }));
this.app.use(express.json());
this.app.use(express.static(resolve(__dirname, 'uploads')));
this.app.use(cors())
}
// Routes that will help you handle HTTP requests.
routes() {
this.app.use('/images', express.static('uploads'));
this.app.use('/users/', userRoutes);
this.app.use('/tokens/', tokenRoutes);
this.app.use('/shop/', shopRoutes);
this.app.use('/products/', productRoutes);
this.app.use('/order/', orderRoutes);
this.app.use('/address/', addressRoutes);
this.app.use("/creditCard/", creditCardRoutes)
}
}
// Exporting express
export default new App().app;