-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathapp.js
37 lines (31 loc) · 1.16 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
const express = require('express');
const morgan = require('morgan');
const cors = require('cors');
const { dbConnection } = require('./config/db');
const { port } = require('./config/constants');
const { options } = require('./config/middleware');
const { facultyRouter, studentRouter, projectRouter, departmentRouter, committeeRouter, libraryRouter } = require('./routes/index');
const app = express();
async function main() {
//DB setup
const connection = await dbConnection();
app.set('connection', connection);
// middleware setup
app.use(express.json());
app.use(express.static(`${__dirname}/public`));
app.use(morgan(':method :url :status :res[content-length] - :response-time ms'));
app.use(cors(options));
//API setup
app.use('/api/faculty', facultyRouter);
app.use('/api/student', studentRouter);
app.use('/api/project', projectRouter);
app.use('/api/department', departmentRouter);
app.use('/api/committee', committeeRouter);
app.use('/api/library', libraryRouter);
return app;
}
main().then(server => {
server.listen(port, () => {
console.log(`server listening on port ${port}`);
})
})