-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
70 lines (61 loc) · 1.59 KB
/
index.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
const express = require("express");
const app = express();
const swaggerUi = require("swagger-ui-express");
const YAML = require("yamljs");
const swaggerDocument = YAML.load("./swagger.yaml");
const fileUpload = require("express-fileupload");
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use(express.json());
app.use(fileUpload());
let courses = [
{
id: "11",
name: "Learn Reactjs",
price: 299,
},
{
id: "12",
name: "Learn Angular",
price: 299,
},
{
id: "13",
name: "Learn Django",
price: 399,
},
];
app.get("/", (req, res) => {
res.send("hello from ajmal");
});
app.get("/api/v1/lco", (req, res) => {
res.send("hello from lco docs ");
});
app.get("/api/v1/lcoobject", (req, res) => {
res.send({ id: "55", name: "learn backend", price: 299 });
});
app.get("/api/v1/courses", (req, res) => {
res.send(courses);
});
app.get("/api/v1/mycourse/:courseId", (req, res) => {
const myCourse = courses.find((course) => course.id === req.params.courseId);
res.send(myCourse);
});
app.post("/api/v1/addCourse", (req, res) => {
console.log(req.body);
courses.push(req.body);
res.send(true);
});
app.get("/api/v1/coursequery", (req, res) => {
let location = req.query.location;
let device = req.query.device;
res.send({ location, device });
});
app.post("/api/v1/courseupload", (req, res) => {
console.log(req.headers);
const file=req.files.file
let path=__dirname + "/images/"+ Date.now() +".jpg"
file.mv(path,(err)=>{
res.send(true)
})
});
app.listen(4000, () => console.log("Server is running on port 4000"));