-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
92 lines (71 loc) · 2.59 KB
/
index.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// set variable of evironment
require('dotenv').config();
// Import module
const express = require('express');
const cookieParser = require('cookie-parser');
const path = require('path');
const cors = require('cors');
const morgan = require('morgan');
// Import module local file
const loginAPI = require('./src/apis/login.api');
const accountAPI = require('./src/apis/account.api');
const addressAPI = require('./src/apis/address.api');
const userAPI = require('./src/apis/user.api');
const orderAPI = require('./src/apis/order.api');
const adminAPI = require('./src/apis/admin.api');
const saleAPI = require('./src/apis/sale.api');
const deliveryAPI = require('./src/apis/delivery.api');
// Set port
const app = express();
const normalizePort = (port) => parseInt(port, 10);
const PORT = normalizePort(process.env.PORT || 3500);
// Set up server
app.use(
cors({
// Configures the Access-Control-Allow-Origin
origin: process.env.CORS_ORIGIN,
// Configures the Access-Control-Allow-Methods
methods: 'GET, POST, OPTIONS, PUT, PATCH, DELETE',
//Configures the Access-Control-Allow-Headers
allowedHeaders:
'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept',
// Configures the Access-Control-Allow-Credentials
credentials: true,
//Configures the Access-Control-Expose-Headers
exposedHeaders: 'Content-Range,X-Content-Range,Authorization',
// Provides a status code to use for successful OPTIONS requests
optionsSuccessStatus: 200,
})
);
app.use(express.json());
app.use(express.urlencoded({extended : true}));
app.use(cookieParser(process.env.SESSION_SECRET));
app.use(morgan('dev'));
// Connect to MongoDB with mongoose
const mongoose = require('mongoose');
//const MONGO_URL = process.env.MONGO_URL ? process.env.MONGO_URL : process.env.MONGO_URL_LOCAL;
mongoose.connect(process.env.MONGO_URL || process.env.MONGO_URL_LOCAL, {
useNewUrlParser: true,
useUnifiedTopology: true
});
// Listening ......
app.listen(PORT,()=>{
console.log('Server is listening on port',PORT);
})
// use cac API
// API chuc nang login
app.use('/auth/login', loginAPI);
// API chuc nang SignUp, change password
app.use('/signup',accountAPI);
// API chuc nang lay dia chi
app.use('/address',addressAPI);
// API chuc nang lien quan user
app.use('/user',userAPI);
// API chuc nang lien quan order
app.use('/order', orderAPI);
// API cho phan he Admin
app.use('/admin', adminAPI);
// API cho phan he sale business
app.use('/sale', saleAPI);
// API cho phan he delivery business
app.use('/delivery', deliveryAPI);