-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
executable file
·77 lines (65 loc) · 2.33 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
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
const express = require('express');
const bodyParser = require('body-parser');
var app = express();
app.use('/uploads', express.static('uploads'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
const db = require('./src/Model/index.js');
db.sequelize.sync();
app.use((req, res, next) => {
// res.header('Access-Control-Allow-Origin', '*');
// res.header(
// 'Access-Control-Allow-Headers,Origin,X-Requested-With,Content-Type',
// 'Accept'
// );
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type,Authorization');
if (req.method === 'OPTIONS') {
req.header('Access-Control-Allow-Methods', 'PUT,POST,DELETE,GET');
return res.status(200).json({});
}
next();
});
var userRoute = require('./src/Route/admin.js');
var productRoute = require('./src/Route/product.js');
var categoryRoute = require('./src/Route/category');
var investRoute = require('./src/Route/invest');
var problemsRoute = require('./src/Route/problem.js');
var employeeRoute = require('./src/Route/employee.js');
var designationRoute = require('./src/Route/designation.js');
var taskRoute = require('./src/Route/task.js');
var orderRoute = require('./src/Route/order.js');
var orderDetails = require('./src/Route/orderDetails.js');
var moenyRequestRoute = require('./src/Route/moneyRequest');
var expanseRoute = require('./src/Route/expanse');
var feedbackRoute = require('./src/Route/feedback');
app.use('/api/admin', userRoute);
app.use('/api/product', productRoute);
app.use('/api/category', categoryRoute);
app.use('/api/invest', investRoute);
app.use('/api/problem', problemsRoute);
app.use('/api/employee', employeeRoute);
app.use('/api/designation', designationRoute);
app.use('/api/task', taskRoute);
app.use('/api/order', orderRoute);
app.use('/api/orderDetails', orderDetails);
app.use('/api/moneyRequest', moenyRequestRoute);
app.use('/api/expanse', expanseRoute);
app.use('/api/feedback', feedbackRoute);
app.use((req, res, next) => {
const error = new Error('Not found');
error.status = 400;
next(error);
});
app.use((error, req, res, next) => {
res.status(error.status || 500);
res.json({
error: {
message: error.message,
},
});
});
app.listen('3001', () => {
console.log('Server started on port 3000');
});