-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (48 loc) · 2.02 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
const express = require("express");
const mongoose = require('mongoose');
const fileUpload = require('express-fileupload');
const YAML = require('yamljs');
const swaggerUi = require('swagger-ui-express');
const UserAPIs = require("./APIs/User");
const AnimalAPIs = require("./APIs/Animal");
const AuthenticationAPIs = require("./APIs/Authentication");
const SearchAPIs = require("./APIs/Search");
//----------- Initialisation -------------
const app = express();
const port = 4000;
const swaggerDocument = YAML.load("./swagger.yaml");
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use(express.json());
app.use(fileUpload({
createParentPath: true,
}))
app.use("/photos", express.static("photos"));
mongoose.connect('mongodb://localhost:27017/dogcatmatcher');
// const db_user = process.env.MONGO_USERNAME;
// const db_password = process.env.MONGO_PASSWORD;
// const db = process.env.MONGO_DATABASE;
// mongoose.connect(
// 'mongodb://' + db_user + ':' + db_password + '@' + db + ':27017/dogcatmatcher');
//----------- API endpoints --------------
app.get("/api/user/:userId", UserAPIs.GetUserHandler);
app.post("/api/user", UserAPIs.PostUserHandler);
app.put("/api/user", UserAPIs.PutUserDetailsHandler);
app.delete("/api/user", UserAPIs.DeleteUserHandler);
app.get("/api/animals", AnimalAPIs.GetAnimalListHandler);
app.get("/api/animal/:id", AnimalAPIs.GetAnimalByIdHandler);
app.post("/api/animal", AnimalAPIs.PostAnimalHandler);
app.put("/api/animal", AnimalAPIs.PutAnimalHandler);
app.delete("/api/animal", AnimalAPIs.DeleteAnimalHandler);
app.get("/api/search/:tag", SearchAPIs.SearchAnimalListHandler);
app.post("/api/login", AuthenticationAPIs.LoginHandler);
app.post("/api/uploadPhoto", AnimalAPIs.UploadAnimalPhotoHandler);
app.get("/api", (req, res) => {
console.log("GET /api")
res.sendStatus(200)
});
// app.use("/", express.static("build"));
//------------ Start server ----------------
app.listen(port, () => {
console.log("Server successfully started at " + port.toString()
)
});