-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.js
63 lines (58 loc) · 1.6 KB
/
api.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
/* Imports */
require("dotenv").config();
const methodOverride = require("method-override");
const fileupload = require("express-fileupload");
const bodyParser = require("body-parser");
const express = require("express");
const helmet = require("helmet");
const cors = require("cors");
const app = express();
const { extended, method } = require("./config");
const {
download,
upload,
login,
purge,
bulk,
getAllByPath,
getAllFiles,
setLastVersion,
remove,
recover,
downloadPDF,
isAuthenticated,
getPersons,
updateTable,
addPerson,
} = require("./controllers/actioner");
const { auth } = require("./middlewares/auth");
/* Configuration */
app.use(bodyParser.urlencoded(extended));
app.use(methodOverride(method));
app.use(express.json());
app.use(fileupload());
app.use(helmet());
app.use(cors());
/* GETs */
app.get("/", getAllByPath);
app.get("/download", download);
app.get("/download/pdf", downloadPDF);
app.get("/getAllFiles", auth, getAllFiles);
app.get("/isAuthenticated", isAuthenticated);
app.get("/persons", auth, getPersons);
/* POSTs */
app.post("/", auth, upload);
app.post("/login", login);
app.post("/purge", auth, purge);
app.post("/bulk", auth, bulk);
app.post("/recover", auth, recover);
app.post("/update", auth, updateTable);
app.post("/lastversion", auth, setLastVersion);
app.post("/persons", auth, addPerson);
/* DELETEs */
app.delete("/", auth, remove);
/* LISTEN */
app.listen(process.env.PORT, (err) => {
if (err) console.log(err);
console.log("API Desplegada:", `http://localhost:${process.env.PORT}`);
});