-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
67 lines (49 loc) · 1.65 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
'use strict';
var SwaggerExpress = require('swagger-express-mw');
var app = require('express')();
const bodyParser = require('body-parser');
const dbConfig = require('./config/database.js');
const mongoose = require('mongoose');
module.exports = app; // for testing
app.use(
function crossOrigin(req,res,next){
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
return next();
}
);
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
mongoose.Promise = global.Promise;
// Connecting to the database
mongoose.connect(dbConfig.url, {
useNewUrlParser: true
}).then(() => {
console.log("Successfully connected to the database");
}).catch(err => {
console.log('Could not connect to the database. Exiting now...', err);
process.exit();
});
app.get('/', (req, res) => {
res.json({"message": "Welcome to our fabric company API"});
});
require('./api/routes/user.js')(app);
require('./api/routes/admin.js')(app);
require('./api/routes/order.js')(app);
require('./api/routes/process-table.js')(app);
require('./api/routes/colorCat.js')(app);
require('./api/routes/color.js')(app);
require('./api/routes/yarn.js')(app);
require('./api/routes/supplier.js')(app);
var config = {
appRoot: __dirname // required config
};
SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) { throw err; }
// install middleware
swaggerExpress.register(app);
app.listen(3000, () => {
console.log("Server is listening on port 3000");
});
});