-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
73 lines (60 loc) · 1.63 KB
/
app.js
File metadata and controls
73 lines (60 loc) · 1.63 KB
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
const express = require('express');
const fs = require('fs');
const path = require('path');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const {dbConnect} = require('./server');
const cors = require("cors");
const swaggerUI = require('swagger-ui-express');
const swaggerJsDoc = require('swagger-jsdoc');
const app = express();
//my routes
const authRoutes = require("./routes/authRoutes");
const courseRoutes = require("./routes/courseRoutes");
const userRoutes = require("./routes/userRoutes");
//swagger
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "Library API",
version: "1.0.0",
description: "A simple Express Library API"
},
servers:[
{
url : "http://localhost:3001/api"
}
],
},
apis: ["./routes/*.js"]
}
const specs = swaggerJsDoc(options);
app.use("/api-docs", swaggerUI.serve,swaggerUI.setup(specs))
app.use(
bodyParser.json()
);
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(cookieParser());
app.use(cors());
// create a write stream (in append mode) for the log file
const accessLogStream = fs.createWriteStream(
path.join(__dirname, 'logs/access.log'), { flags: 'a' }
);
// setup the logger middleware using the "combined" format
app.use(morgan('combined', { stream: accessLogStream }));
//my routes
app.use("/api", authRoutes)
app.use("/api", courseRoutes)
app.use("/api", userRoutes)
const port = 3001;
app.listen(port, () => {
console.log(`app is running at ${port}`);
});
app.get('/', (req, res) => {
res.send('Hello World!');
});
module.exports = app;