forked from COROTANjayson/cso_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (57 loc) · 1.78 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
const cors = require("cors");
const express = require("express");
// const bp = require("body-parser");
const passport = require("passport");
const { connect } = require("mongoose");
const { success, error } = require("consola");
const http = require('http');
// Bring in the app constants
const { DB, PORT } = require("./config");
// Initialize the application
const app = express();
// Socket io
const socketio = require('socket.io');
// Initialize and Connect to socket.io
const server = http.createServer(app);
const io = socketio(server);
// Middlewares
// app.use(cors());
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.use(passport.initialize());
/* require("./middlewares/passport")(passport); */
// User Router Middleware
app.use("/api/users", require("./routes/users"));
app.use("/api/FAQ", require("./routes/FAQ"));
app.use("/api/students", require("./routes/students"));
app.use("/api/query", require("./routes/query"));
app.use("/api/sender", require("./routes/sender"));
app.use("/api/category", require("./routes/category"));
app.use('/api/sms', require('./routes/sms')(io));
// Testing router (can be deleted)
app.use('/api/nlp',require('./routes/nlp'))
const startApp = async () => {
try {
// Connection With DB
await connect(DB, {
useFindAndModify: false,
useUnifiedTopology: true,
useNewUrlParser: true
});
success({
message: `Successfully connected with the Database \n${DB}`,
badge: true
});
// Start Listenting for the server on PORT
server.listen(PORT, () =>
success({ message: `Server started on PORT ${PORT}`, badge: true })
);
} catch (err) {
error({
message: `Unable to connect with Database \n${err}`,
badge: true
});
startApp();
}
};
startApp();