-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
38 lines (28 loc) · 1.23 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
38
const express = require("express");
const app = express();
require('dotenv').config()
const getRoutes = require("./controller/get");
const file = require('./controller/file');
const showFile = require("./controller/showFile");
const connectDatabase = require('./database/connection');
const downloadFile = require('./controller/download');
const deletes = require("./controller/delete");
var bodyParser = require('body-parser')
const rateLimiter = require('./validators/uploadLimiter');
app.use(bodyParser.urlencoded({
extended: true
}));
app.use((req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers: Content-Type, Custom-Header");
next();
})
app.get("/",getRoutes.index); //app base url route
app.post("/api/uploadfile", file.uploadFile,rateLimiter.uploadLimiter); //when URL hits BASE_URL/uploadfile route
app.post("/api/file",showFile.show,deletes.deleteFiles); //when URL hits BASE_URL/file route
app.get(`/files/download/:uuid`,downloadFile.downloadFile); //when URL hits /files/download/any_uuid
connectDatabase(); //connect database
/**listen on port and serve */
app.listen(process.env.PORT,()=>{
console.log(`App running at ${process.env.APP_BASE_URL}`);
});