-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.js
55 lines (42 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
48
49
50
51
52
53
54
55
const express = require('express');
var cors = require('cors')
const app = express();
const PORT = 8000;
var usersRouter = require('./routes/user_routes');
const swStats = require('swagger-stats');
var swaggerUi = require('swagger-ui-express')
var swaggerDocument = require('./docs/swagger.json');
const path = require('path');
app.use(swStats.getMiddleware({ swaggerSpec: swaggerDocument }));
app.use(cors())
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
//connecting to db
var connection = require('./middlewares/connection').then(db => {
if (db != undefined) {
console.log("Connection Success")
//initializing admin bro
var adminBroRouter = require('./routes/admin_bro');
//setting up admin bro
app.use('/admin', adminBroRouter)
} else {
console.log("Connection Failed")
}
}).catch(err => {
console.log("connection failed due to " + err)
})
//setting up swagger
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
console.log("Swagger running at port 8000 at /api-docs")
//setting up route for user related API's
app.use('/api/v1/users', usersRouter);
// Serve static files from the React app
app.use(express.static(path.join(__dirname, 'ui/dist')));
// Handle other routes and return the React app
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, 'ui/dist/index.html'));
});
app.listen(PORT, () => {
console.log(`⚡️[server]: Server is running at https://localhost:${PORT}`);
});
module.exports = app;